我需要在 Nokogiri 中重新创建这部分 XML 文档:
<propertiesJMeter>
<jmeter.save.saveservice.thread_counts>
true
</jmeter.save.saveservice.thread_counts>
</propertiesJMeter>
我像这样用 Nokogiri::XML::Builder 构建它,这里只是有问题的部分:
propertiesJMeter {
jmeter.save.saveservice.thread_counts 'true'
}
结果不正确,因为我不需要那个类变量并且我想保存命名空间结构:
<propertiesJMeter>
<jmeter class="save saveservice thread_counts">
true
</jmeter>
</propertiesJMeter>
最佳答案
发布“nokogiri-talk”组的答案,这对我有帮助
The issue is that
jmeter.save
is interpreted by Nokogiri Builder as a "Tag Attribute Short Cut" (as you can read about at http://www.rubydoc.info/github/sparklemotion/nokogiri/Nokogiri/XML/Builder).
To make a tag with a "." in the tagname, you'll need to make sure ruby doesn't interpret the "." as an instance method call. This works:
propertiesJMeter { send "jmeter.save.saveservice.thread_counts", 'true' }
and emits
<propertiesJMeter> <jmeter.save.saveservice.thread_counts>true</jmeter.save.saveservice.thread_counts> </propertiesJMeter>
关于ruby - 如何在 Nokogiri 中创建具有长命名空间的 XML,除以点,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32839813/