Satchel
Satchel

Reputation: 16724

How do I use Nokogiri XML Builder with a field that is the word "text"?

I think "text" must be a special form because when I use xml.text "hello" the tag doesn't appear in the xml doc. Whatever follows that tag is simply listed without a . I tried to use send.(:"text", "hello") but that doesn't work either.

Ideas?

Upvotes: 3

Views: 413

Answers (2)

Dave
Dave

Reputation: 4694

Which means you need to put an underscore after the tag name.

Just to clarify with an example for anyone else who might be searching for this (such as I was):

builder = Nokogiri::XML::Builder.new do |xml|
  xml.questions {
    xml.question {
      xml.text_ "What is your name?"
    }
    xml.question {
      xml.text_ "What is your favourite colour?"
    }
  }
end

Upvotes: 4

Satchel
Satchel

Reputation: 16724

I solved it using the "special tags" in Nokogiri.

Upvotes: 2

Related Questions