Nokogiri put tags with separation

0
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>
    
asked by anonymous 03.05.2018 / 21:43

1 answer

0

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    
    
19.05.2018 / 04:40