1
votes

I'm trying to use Nokogiri::XML::Builder.new to create a structure whose root element is called 'file' rather than 'root'.

All of the examples on the Nokogiri documentation site use <root>, and I can't seem to find a way to get it to work with an alternative element name. My code is as follows:

    builder = Nokogiri::XML::Builder.new do |xml|
xml.file(:id_=> "", :format=> "", :mimetype=>"", :size=>""){
    xml.location(:type=>"")
    xml.checksum(:type=>"")
    }

That doesn't seem to work. I'm not sure what's going wrong. Any pointers?

Thanks.

1
Edited to put backquotes around <root> in your text. Otherwise it becomes invisible. - LarsH
"Doesn't seem to work" = ? What is the behavior observed? The top-level element is still named <root> instead of <file>? - LarsH

1 Answers

2
votes

Works for me..

ruby-1.9.2-p0 > Nokogiri::XML::Builder.new {|b| b.file }.to_xml
 => "<?xml version=\"1.0\"?>\n<file/>\n" 
ruby-1.9.2-p0 > Nokogiri::VERSION
 => "1.4.4"