I want to output an xml file in a specific way only using REXML with Ruby. Here is what the xml file looks like:
<desc>
<id>2408</id>
<who name="Joe Silva">joe@silva.com</who>
<when>Today</when>
<thetext>Hello World</thetext>
</desc>
<desc>
<id>2409</id>
<who name="Joe Silva2">joe2@silva.com</who>
<when>Future</when>
<thetext>Hello World Again</thetext>
</desc>
So far, here is the code I use:
document.elements.each("//desc") {
|e| e.elements.each
|i| puts "#{i.name} : #{i.text}"
puts "\n"
}
This gives me the following output:
commentid : 2408
who : joe@silva.com
bug_when : Today
thetext : Hello World
commentid : 2409
who : joe2@silva.com
bug_when : Future
thetext : Hello World Again
I can access each tag's text but not their attributes. How do I get access to the attributes and get an output with the name attribute?
So the output I want is:
commentid : 2408
name : Joe Silva
who : joe@silva.com
bug_when : Today
thetext : Hello World
Let me know if further explanation is required.