是否可以在Ruby中迭代特定的XML标记?在我来说,我想遍历desc
标签下面XML代码:在Ruby中是否有一种迭代遍历特定XML标记的方法?
<desc>
<id>2408</id>
<who name="Joe Silva">[email protected]</who>
<when>Today</when>
<thetext>Hello World</thetext>
</desc>
<desc>
<id>2409</id>
<who name="Joe Silva2">[email protected]</who>
<when>Future</when>
<thetext>Hello World Again</thetext>
</desc>
到目前为止,这里是我使用的代码:
xml_doc = agent.get("www.somewhere.com/file.xml")
document = REXML::Document.new(xml_doc.body);
# iterate over desc here
我想遍历每个desc
标记,以便我得到以下输出:
commentid : 2408
name : Joe Silva
who : [email protected]
bug_when : Today
thetext : Hello World
commentid : 2409
name : Joe Silva2
who : [email protected]
bug_when : Future
thetext : Hello World Again
有什么建议吗?
如何http://stackoverflow.com/questions这*不*副本/ 28157224 /如何到获得最属性-的-AN-XML标签的使用,红宝石与-REXML? – 2015-01-27 00:48:47
使用XPath遍历*节点列表*。 – 2015-01-27 04:20:23