Builder Options for Ruby Nokogiri: Standalone

I would like to create XML that starts with:

<?xml version = "1.0" encoding = "UTF-8" standalone ="no"?> 

But I cannot find how to add the " standalone " parameter in the Nokogiri documentation.

My code looks like this:

 builder = Nokogiri::XML::Builder.new(:encoding => 'UTF-8', :standalone => 'no') do |xml| 

But that fails when Nokigiri finds :standalone . Works :encoding .

+4
source share
1 answer

In this case, Nokogiri :: XML :: Builder can use an existing XML document using the with method:

 xml = Nokogiri::XML('<?xml version = "1.0" encoding = "UTF-8" standalone ="no"?>') puts Nokogiri::XML::Builder.with(xml) { |x| x.awesome }.to_xml <?xml version="1.0" encoding="UTF-8" standalone="no"?> <awesome/> 
+6
source

All Articles