比方说,我有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