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.
Nokogiri builder can be used for building XML and HTML documents. The builder allows two forms. When the builder is supplied with a block that has a parameter, the outside scope is maintained.
This installation should only take a few seconds, and your output should look something like: Because Nokogiri is a C extension, it requires that you have a C compiler toolchain, Ruby development header files, and some system dependencies installed. The following may work for you if you have an appropriately-configured system:
There are a few ways to ask exploratory questions: The Ruby Discord chat server is active at https://discord.gg/UyQnKrT Open an issue using the "Help Request" template at https://github.com/sparklemotion/nokogiri/issues Please do not mail the maintainers at their personal addresses.
It is fast and standards-compliant by relying on native parsers like libxml2 (C) and xerces (Java). Some guiding principles Nokogiri tries to follow:
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/>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With