Must use hyphen in function name Builder

I am trying to use Builder to create an XML document for a project that I am working on. Xml has a very strict structure, so I cannot change it. The problem I am facing is this. I am trying to add a child to a node. "linking-phrase-list" The name of the child should be "linking-phrase". Therefore, for this I would call:

test = Builder.new do |xml|
  xml.map {
    xml.send(:"linking-phrase-list") {
      xml.linking-phrase("label" => "edge1", "id" => "idedge1")
    }
  }
end

Of course, Ruby interprets this as (xml.linking)-phrase()being completely different from what I want. So I need to know if there is a way to convince Ruby of calling a function not two? Or to tell nokogiri what I mean when I do not use this function.

+3
source share
2 answers

tag!, .

test = Builder.new do |xml|
  xml.map {
    xml.tag!("linking-phrase-list") {
      xml.tag!("linking-phrase", "label" => "edge1", "id" => "idedge1")
    }
  }
end
+5

, , send:

require 'nokogiri'

test = Nokogiri::XML::Builder.new do |xml|
  xml.map {
    xml.send(:"linking-phrase-list") {
      xml.send(:"linking-phrase", "label" => "edge1", "id" => "idedge1")
    }
  }
end

puts test.to_xml

:

<?xml version="1.0"?>
<map>
  <linking-phrase-list>
    <linking-phrase label="edge1" id="idedge1"/>
  </linking-phrase-list>
</map>
+1

All Articles