我使用引入nokogiri解析一些XML看起來有點像:使用XPath選擇根和孩子匹配表達式
<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
在迭代時,我可以使用什麼表達式從第一個節點獲取?
請閱讀 「[MCVE]」。您的XML無效並且您的源代碼無法運行。不要要求我們編寫代碼來測試你的代碼。 –