Nokogiri::XML::Builder: Need to use the string "send" as element name
builder, nokogiri, ruby, send
Solution
From the docs:
The builder works by taking advantage of method_missing. Unfortunately some methods are defined in ruby that are difficult or dangerous to remove. You may want to create tags with the name “type”, “class”, and “id” for example. In that case, you can use an underscore to disambiguate your tag name from the method call.
So check the following:
irb(main):007:0> Nokogiri::XML::Builder.new { |xml| xml.send_ "foo" }.to_xml
=> "<?xml version=\"1.0\"?>\n<send>foo</send>\n"
Problem
I am writing an application to generate XML files as input to SipP. One tag frequently used by SipP is 'send' The problem is, when I use nokogiri to build the xml for me ``` builder = Nokogiri::XML::Builder.new do |xml| xml.send "Some Content" end ``` I get this ``` <?xml version="1.0"?> <Some Content/> ``` The same happens when I do this: ``` builder = Nokogiri::XML::Builder.new do |xml| xml.send(:'send', "Some Content") end ``` I can't spell 'SEND' in capital letters, because SipP won't understand it that way. Any ideas how to force nokogiri to create an element with the name 'send'? Thank you