使用 Nokogiri 创建带点 `.` 的命名空间 XML 节点

Create namespaced XML nodes with dot `.` using Nokogiri

我正在使用 Nokogiri 生成 XML:

Nokogiri::XML::Builder.new do |xml|
  xml['nitf'].nitf('xmlns:nitf' => 'bar') {
  // some nodes here

    xml.body {
      xml.head {
        //some nodes here
      }
    }
  }
end

输出为

<nitf:nitf xmlns:nitf="http://iptc.org/std/NITF/2006-10-18/">
  // some nodes here
  <nitf:body>
    <nitf:head>
      // some nodes here
    </nitf:head>
  </nitf:body>
</nitf:nitf>

但我需要 <nitf:body.head> 而不是 <nitf:head>。如何达到这样的效果?

使用#send解决:

xml.body {
  xml.send('body.head') {
    ...
  }
}


<nitf:body>
  <nitf:body.head>
  ...
  </nitf:body.head>
</nitf:body>