Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Builder options on Ruby Nokogiri :standalone

Tags:

xml

ruby

nokogiri

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.

like image 608
ricardo Avatar asked Aug 10 '12 14:08

ricardo


People also ask

What is Nokogiri builder used for?

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.

How long does it take to install Nokogiri?

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:

How do I ask for help with Nokogiri?

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.

What programming language does Nokogiri use?

It is fast and standards-compliant by relying on native parsers like libxml2 (C) and xerces (Java). Some guiding principles Nokogiri tries to follow:


Video Answer


1 Answers

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/>
like image 111
the Tin Man Avatar answered Oct 04 '22 05:10

the Tin Man