How can I generate XML with Nokogiri without "<?xml version=..."? [duplicate] How can I generate XML with Nokogiri without "<?xml version=..."? [duplicate] xml xml

How can I generate XML with Nokogiri without "<?xml version=..."? [duplicate]


Maybe take just the root node of the current Document object being built – .doc – instead of the whole document?

builder.doc.root.to_s


A quick and dirty answer is to tell Nokogiri to reparse the resulting output, then look at the root:

require 'nokogiri'builder = Nokogiri::XML::Builder.new do   request {    data '1'  }endputs Nokogiri::XML(builder.to_xml).root.to_xml

Which outputs:

<request>  <data>1</data></request>