0
teste = Nokogiri::XML::DocumentFragment.parse("") Nokogiri::XML::Builder.with( teste ){ |x| x.exemplo "teste xml" } puts teste.to_xml
Message I printed out
<exemplo>teste xml</exemplo>
Message you desired
<ns:exemplo>teste xml</ns:exemplo>
0
teste = Nokogiri::XML::DocumentFragment.parse("") Nokogiri::XML::Builder.with( teste ){ |x| x.exemplo "teste xml" } puts teste.to_xml
Message I printed out
<exemplo>teste xml</exemplo>
Message you desired
<ns:exemplo>teste xml</ns:exemplo>
0
From what I understand, you want to use namespaces (the tags with separation). A namespace needs to be declared associated with a URI(Uniform Resource Identifier). If you need a more detailed explanation you can find at: https://imasters.com.br/artigo/161/dotnet/entendendo-namespaces/? trace=1519021197&source=single
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
Browser other questions tagged ruby-on-rails ruby
You are not signed in. Login or sign up in order to post.
I already solved this problem, but the code is correct. The interesting thing is that if you want to use the tag ns2, xml['ns2']. tagNamespace1 "Content"
– Magic Oz