Builder options on Ruby Nokogiri :standalone

nokogiri, ruby, xml

Solution

The way around this is to tell Nokogiri::XML::Builder to use an existing XML document by 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/>

Problem

I would like to to create XML that begins with: ``` <?xml version = "1.0" encoding = "UTF-8" standalone ="no"?> ``` But I cannot find how to add the '`standalone`' option in the Nokogiri documentation. My code is like this: ``` builder = Nokogiri::XML::Builder.new(:encoding => 'UTF-8', :standalone => 'no') do |xml| ``` But it fails when Nokogiri finds `:standalone`. The `:encoding` works.

Original source