【发布时间】:2016-07-24 13:12:30
【问题描述】:
我正在使用 Nokogiri 解析一些看起来像这样的 XML:
<item name="item one">
<other name="other name"/>
<third />
</item>
<item name="item two">
<other />
<third />
</item>
我正在使用 Nokogiri 解析项目,如下所示:
xmldoc.xpath("//item").each do |node|
node.xpath("//*[@name]") # Gives me *all* elements in the doc
node.xpath(".//*[@name]") # Gives me child elements of the item
end
当我迭代时,我可以使用什么表达式从第一个节点获取[item, other]?
【问题讨论】:
-
请阅读“minimal reproducible example”。您的 XML 无效并且您的源代码无法运行。不要要求我们编写代码只是为了测试您的代码。