teste = Nokogiri::XML::DocumentFragment.parse("") Nokogiri::XML::Builder.with( teste ){ |x| x.exemplo "teste xml" } puts teste.to_xml
Message you printed
<exemplo>teste xml</exemplo>
Message as desired
<ns:exemplo>teste xml</ns:exemplo>
teste = Nokogiri::XML::DocumentFragment.parse("") Nokogiri::XML::Builder.with( teste ){ |x| x.exemplo "teste xml" } puts teste.to_xml
Message you printed
<exemplo>teste xml</exemplo>
Message as desired
<ns:exemplo>teste xml</ns:exemplo>
As far as I understand, you want to use namespaces (the separator tags). A namespace must be declared associated with a Uniform Resource Identifier (URI). If you need a more detailed explanation you can find at: link
You can create a namespace with gem Nokogiri as an example below:
require 'nokogiri'
NAMESPACES = {
"xmlns:ns" => "http://www.w3.org/1999/xhtml",
"xmlns:ns2" => "http://www.w3.org/1999/XSL/Transform"
}
ex = Nokogiri::XML::Builder.new { |xml|
xml['ns'].exemplo(NAMESPACES) do
xml.tagNamespace1 "Conteudo"
end
}
puts ex.to_xml