<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
		>
<channel>
	<title>Comments on: DOM Processing</title>
	<atom:link href="http://blog.naxsoft.com/archives/406/dom-processing/feed" rel="self" type="application/rss+xml" />
	<link>http://blog.naxsoft.com/archives/406/dom-processing</link>
	<description>Mind-dump</description>
	<lastBuildDate>Mon, 30 Mar 2009 15:46:50 -0400</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9.1</generator>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
		<item>
		<title>By: Guillaume</title>
		<link>http://blog.naxsoft.com/archives/406/dom-processing/comment-page-1#comment-162</link>
		<dc:creator>Guillaume</dc:creator>
		<pubDate>Wed, 07 Mar 2007 03:45:00 +0000</pubDate>
		<guid isPermaLink="false">http://blog.naxsoft.com/?p=406#comment-162</guid>
		<description>I did some XML processing recently with HPricot in ruby. Your example would look something like this:&lt;BR/&gt;&lt;BR/&gt;require &#039;Hpricot&#039;&lt;BR/&gt;&lt;BR/&gt;doc = HPricot(open(&#039;po.xml&#039;))&lt;BR/&gt;sum = 0&lt;BR/&gt;doc.search(&#039;item&#039;) do &#124;item&#124;&lt;BR/&gt;    puts item.search(&#039;productname&#039;).first&lt;BR/&gt;    sum += item.search(&#039;usprice&#039;).first.to_f * item.search(&#039;quantity&#039;).first.to_i&lt;BR/&gt;end&lt;BR/&gt;&lt;BR/&gt;If you instead had tags like&lt;BR/&gt;&lt;item partNum=&quot;xxx&quot; price=&quot;39.99&quot; qty=&quot;2&quot; /&gt; you would access that like this:&lt;BR/&gt;&lt;BR/&gt;doc.search(&#039;item&#039;) do &#124;item&#124;&lt;BR/&gt;    puts item[&#039;productname&#039;]&lt;BR/&gt;    sum += item[&#039;usprice&#039;].to_f * item[&#039;quantity&#039;].to_i&lt;BR/&gt;end</description>
		<content:encoded><![CDATA[<p>I did some XML processing recently with HPricot in ruby. Your example would look something like this:</p>
<p>require &#8216;Hpricot&#8217;</p>
<p>doc = HPricot(open(&#8216;po.xml&#8217;))<br />sum = 0<br />doc.search(&#8216;item&#8217;) do |item|<br />    puts item.search(&#8216;productname&#8217;).first<br />    sum += item.search(&#8216;usprice&#8217;).first.to_f * item.search(&#8216;quantity&#8217;).first.to_i<br />end</p>
<p>If you instead had tags like<br />&lt;item partNum=&#8221;xxx&#8221; price=&#8221;39.99&#8243; qty=&#8221;2&#8243; /&gt; you would access that like this:</p>
<p>doc.search(&#8216;item&#8217;) do |item|<br />    puts item['productname']<br />    sum += item['usprice'].to_f * item['quantity'].to_i<br />end</p>
]]></content:encoded>
	</item>
</channel>
</rss>
