Is it possible to iterate over a specific XML tag in Ruby? In my case I want iterate over the desc tag in the following XML code:
<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>
So far, here is the code I use:
xml_doc = agent.get("www.somewhere.com/file.xml")
document = REXML::Document.new(xml_doc.body);
# iterate over desc here
I want to iterate over each desc tags so that I get the following output:
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
Any suggestions?
Nokogiri example that includes the
nameattribute for thewhonode: