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

I think that β€œtext” should be a special form, because when I use xml.text β€œhello”, the tag does not appear in the xml document. Regardless of the fact that the tag is simply specified without a. I tried to use send. (: "Text", "hello"), but this also does not work.

Ideas?

+3
source share
2 answers

I solved this using the "special tags" in Nokigiri.

+2
source

This means that you need to add an underscore after the tag name.

Just for clarification with an example for someone who can search for it (like 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
+3
source

Source: https://habr.com/ru/post/1747793/


All Articles