比方說,我有XML,看起來像這樣:獲得一個子元素與給定的名稱以引入nokogiri
<paper>
<header>
</header>
<body>
<paragraph>
</paragraph>
</body>
<conclusion>
</conclusion>
</paper>
有沒有辦法我就可以得到conclusion
,未做一個醜陋的循環,如:
for child in paper.children do
if child.name == "conclusion"
conclusion = child
end
end
puts conclusion
理想情況下,類似python的Element.find('conclusion')
。
你見過[本教程(http://www.nokogiri.org/tutorials/searching_a_xml_html_document.html)?我發現它通過谷歌搜索「nokogiri查找元素的名稱」 – alexanderbird