2016-04-06 4 views
0

ich Nokogiri bin mit XML zu generieren:`.` mit Nokogiri

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

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

Der Ausgang

<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> 

ist Aber ich brauche <nitf:body.head> statt <nitf:head> haben. Wie erreiche ich ein solches Ergebnis?

Antwort

1

Gelöst mit #send:

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


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