【问题标题】:Nokogiri put tags with separationNokogiri 将标签与分离
【发布时间】:2018-05-04 11:59:28
【问题描述】:

我想单独发送消息:

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>

【问题讨论】:

  • 试试puts teste.to_text
  • 我想给你发消息:teste

标签: ruby-on-rails ruby ruby-on-rails-3 ruby-on-rails-4 rubygems


【解决方案1】:

这是一个工作示例:

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 语法。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2022-08-16
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-02-10
    相关资源
    最近更新 更多