tags:

views:

124

answers:

1

I have a XML File in the following format:

<?xml version='1.0' encoding='UTF-8'?>

<entry xmlns='http://www.w3.org/2005/Atom' xmlns:gwo='http://schemas.google.com/analytics/websiteoptimizer/2009' xmlns:app='http://www.w3.org/2007/app' xmlns:gd='http://schemas.google.com/g/2005' gd:etag='W/&quot;DUYGRX85fCp7I2A9WxFWEkQ.&quot;'><id>https://www.google.com/analytics/feeds/websiteoptimizer/experiments/1025910&lt;/id&gt;&lt;updated&gt;2010-05-31T02:12:04.124-07:00&lt;/updated&gt;&lt;app:edited&gt;2010-05-31T02:12:04.124-07:00&lt;/app:edited&gt;&lt;title&gt;Flow Experiment</title><link rel='gwo:goalUrl' type='text/html' href='http://cart.personallifemedia.com/dlg/download.php'/&gt;&lt;link rel='alternate' type='text/html' href='https://www.google.com/websiteoptimizer'/&gt;&lt;link rel='self' type='application/atom+xml' href='https://www.google.com/analytics/feeds/websiteoptimizer/experiments/1025910'/&gt;&lt;gwo:analyticsAccountId&gt;16334726&lt;/gwo:analyticsAccountId&gt;&lt;gwo:autoPruneMode&gt;None&lt;/gwo:autoPruneMode&gt;&lt;gwo:controlScript&gt;.....

I have to parse and get the data for gd:etag and how do I do it?

I was able to get the value using SimpleXML, but i wanted to achieve it in ReXML.

Please do advice.

+1  A: 

presumes only one "entry" tag ...

require "rexml/document"
include REXML
xml=<<EOD
<?xml version='1.0' encoding='UTF-8'?><entry xmlns='http://www.w3.org/2005/Atom' xmlns:gwo='http://schemas.google.com/analytics/websiteoptimizer/2009' xmlns:app='http://www.w3.org/2007/app' xmlns:gd='http://schemas.google.com/g/2005' gd:etag='W/&quot;DUYGRX85fCp7I2A9WxFWEkQ.&quot;'><id>https://www.google.com/analytics/feeds/websiteoptimizer/experiments/1025910&lt;/id&gt;&lt;/entry&gt;
EOD
doc = Document.new xml
doc.elements["entry"].attributes["gd:etag"]

see http://www.germane-software.com/software/rexml/docs/tutorial.html

Straff
Thank you, yup it worked well
Paddy