开发者

Nokogiri: Root element in XML which isn't called 'root'

开发者 https://www.devze.com 2023-01-29 11:55 出处:网络
I\'m trying to use Nokogiri::XML::Builder.new to create a structure whose root element is called \'file\' rather than \'root\'.

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=> "", :mim开发者_Python百科etype=>"", :size=>""){
    xml.location(:type=>"")
    xml.checksum(:type=>"")
    }

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

Thanks.


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

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号