On Thu, Sep 16, 2010 at 4:42 PM, Stuart Clarke
<stuart.clarke1986 / gmail.com> wrote:
> Hey all,
>
> I would like to pick your brains about Rexml and how to report from it.
> For example, I am reading an XML file using references to each XML tag
> like so:
>
> doc.root.each_element("/UserData/List/ItemInfo/Title") {|e|
> =A0report.puts "Title: #{e.text}"
> }
> doc.root.each_element("/UserData/List/ItemInfo/Date") {|e|
> =A0report.puts "Date: #{e.text}"
> }
>
> The 'report.puts' writes this data out to a CSV file. At present I get a
> list of all the titles in the XML file followed a list of the dates.
> What I need it to get the side by side in a CSV file like so
>
> Title =A0 =A0 =A0 =A0 =A0 =A0 Date
> Item1 =A0 =A0 =A0 =A0 =A0 =A0 20th Jan 2009
> Item2 =A0 =A0 =A0 =A0 =A0 =A0 12th Feb 2010
>
> Does anyone have any suggestions on a suitable workflow for this?

Just iterate over all "ItemInfo" elements and print values from sub
elements (which you can select via a relative XPath).

Kind regards

robert

--=20
remember.guy do |as, often| as.you_can - without end
http://blog.rubybestpractices.com/