Roberto Pezzali
Roberto Pezzali

Reputation: 2494

How to use "doc" tag in Nokogiri to build an XML document

I have a problem: I must build an XML document with a <doc> tag. I can use any custom tag except "doc".

I need to use "doc". How can I fix this?

Upvotes: 2

Views: 87

Answers (1)

matt
matt

Reputation: 79723

You can add an underscore to the name to prevent it being seen as an existing method. See the section “Special Tags” in the Nokogiri Builder docs.

Something like:

Nokogiri::XML::Builder.new do |xml|
  # Note the underscore here:
  xml.doc_ "A doc tag"
end

This example produces the following XML (the underscore isn’t included in the tag name):

<?xml version="1.0"?>
<doc>A doc tag</doc>

Upvotes: 4

Related Questions