2016-04-06 106 views
0

我使用引入nokogiri生成XML節點:創建命名空間中的XML用點`.`使用引入nokogiri

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>。如何實現這樣的結果?

回答

1

解決使用#send

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


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