Nokogiri 把标签分开
Nokogiri put tags with separation
我想单独留言:
teste = Nokogiri::XML::DocumentFragment.parse("")
Nokogiri::XML::Builder.with( teste ){ |x|
x.exemplo "teste xml"
}
puts teste.to_xml
消息打印
<exemplo>teste xml</exemplo>
您想要的留言
<ns3:exemplo>teste</ns3:exemplo>
这是一个工作示例:
require 'nokogiri'
teste = Nokogiri::XML::DocumentFragment.parse("")
Nokogiri::XML::Builder.with(teste) do |x|
x.root('xmlns:ns3' => 'Example namespace') do
x['ns3'].example "Example Test"
end
end
puts teste.to_xml
请记住,您必须先定义命名空间,然后才能使用。然后你使用 Nokogiri::XML::Builder#[]
来定义一个命名空间,然后是正常的 Nokogiri 语法。
我想单独留言:
teste = Nokogiri::XML::DocumentFragment.parse("")
Nokogiri::XML::Builder.with( teste ){ |x|
x.exemplo "teste xml"
}
puts teste.to_xml
消息打印
<exemplo>teste xml</exemplo>
您想要的留言
<ns3:exemplo>teste</ns3:exemplo>
这是一个工作示例:
require 'nokogiri'
teste = Nokogiri::XML::DocumentFragment.parse("")
Nokogiri::XML::Builder.with(teste) do |x|
x.root('xmlns:ns3' => 'Example namespace') do
x['ns3'].example "Example Test"
end
end
puts teste.to_xml
请记住,您必须先定义命名空间,然后才能使用。然后你使用 Nokogiri::XML::Builder#[]
来定义一个命名空间,然后是正常的 Nokogiri 语法。