<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	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/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>tov's Blog &#187; Hpricot</title>
	<atom:link href="http://blog.nobody-is-like.me/tag/hpricot/feed/" rel="self" type="application/rss+xml" />
	<link>http://blog.nobody-is-like.me</link>
	<description>Just another (geeky) WordPress weblog</description>
	<lastBuildDate>Tue, 16 Mar 2010 13:43:04 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0.1</generator>
		<item>
		<title>Hpricot: XML to Hash</title>
		<link>http://blog.nobody-is-like.me/2009/03/hpricot-xml-to-hash/</link>
		<comments>http://blog.nobody-is-like.me/2009/03/hpricot-xml-to-hash/#comments</comments>
		<pubDate>Fri, 20 Mar 2009 18:20:09 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Programmierung]]></category>
		<category><![CDATA[Ruby and Rails]]></category>
		<category><![CDATA[Hpricot]]></category>
		<category><![CDATA[Rails]]></category>
		<category><![CDATA[Ruby]]></category>

		<guid isPermaLink="false">http://blog.nobody-is-like.me/?p=21</guid>
		<description><![CDATA[Well: I nearly lost all my hairs about this. Strange that I couldn&#8217;t find something like this in the docs.Situation: I have some XML code from that I need parts being put into a simple hash (see below). The following small ruby snippet does exactly this. Only thing that&#8217;s not working is the &#8220;inner_xml&#8221; part. [...]]]></description>
			<content:encoded><![CDATA[<p>Well: I nearly lost all my hairs about this. Strange that I couldn&#8217;t find something like this in the docs.Situation:</p>
<p>I have some XML code from that I need parts being put into a simple hash (see below).</p>
<p>The following small ruby snippet does exactly this.</p>
<p>Only thing that&#8217;s not working is the  &#8220;inner_xml&#8221; part. I personally don&#8217;t need it but your mileage may vary and you may want to fix the issue (and give me a note)</p>
<pre class="brush: ruby;">
require 'rubygems'
require 'hpricot'
require 'pp'

text = &lt;&lt;eof
&lt;payment&gt;
		&lt;vat&gt;
			&lt;pay_vat&gt;0&lt;/pay_vat&gt;
			&lt;vat_id/&gt;
		&lt;/vat&gt;
		&lt;creditcard&gt;
			&lt;type&gt;master&lt;/type&gt;
			&lt;holder&gt;Franz Fluchsfinger&lt;/holder&gt;
			&lt;company/&gt;
			&lt;no&gt;52660xxxxxxxxxxx79&lt;/no&gt;
			&lt;kpn/&gt;
			&lt;valid_until&gt;09/10&lt;/valid_until&gt;
			&lt;data&gt;Just some data&lt;/data&gt;
			&lt;xml_for_demo&gt;&lt;inner_xml&gt;inner text&lt;/inner_xml&gt;&lt;/xml_for_demo&gt;
			&lt;signature&gt;a5f4e2shortened4b1e523ca873837c8f1c9ea66ee1924d&lt;/signature&gt;
		&lt;/creditcard&gt;
&lt;/payment&gt;
eof

xml =Hpricot.XML(text)
a= xml/&quot;creditcard/*&quot;
h={}
a.each {|b|
	h[b.name] = b.inner_text if b.is_a? Hpricot::Elem
}
pp h	
</pre>
<p>result:</p>
<p>[code]]czozMDE6XCINCnJ1YnkgdGVzdC5yYg0Ke1wiY29tcGFueVwiPSZndDtcIlwiLA0KXCJ4bWxfZm9yX2RlbW9cIj0mZ3Q7XCJpbm5lciB0ZXh0XCIsDXtbJiomXX0KXCJub1wiPSZndDtcIjUyNjYweHh4eHh4eHh4eHg3OVwiLA0KXCJob2xkZXJcIj0mZ3Q7XCJGcmFueiBGbHVjaHNmaW5nZXJcIiwNClwic2lnbmF0e1smKiZdfXVyZVwiPSZndDtcImE1ZjRlMnNob3J0ZW5lZDRiMWU1MjNjYTg3MzgzN2M4ZjFjOWVhNjZlZTE5MjRkXCIsDQpcInR5cGVcIj0mZ3Q7XCJtYXN7WyYqJl19dGVyXCIsDQpcInZhbGlkX3VudGlsXCI9Jmd0O1wiMDkvMTBcIiwNClwia3BuXCI9Jmd0O1wiXCIsDQpcImRhdGFcIj0mZ3Q7XCJKdXN0IHNvbWUgZGF0YXtbJiomXX1cIn0NClwiO3tbJiomXX0=[[/code]</p>
<p>Btw.: I found the solution partly on <a href="http://railsforum.com/viewtopic.php?id=22055">http://railsforum.com/viewtopic.php?id=22055</a></p>
]]></content:encoded>
			<wfw:commentRss>http://blog.nobody-is-like.me/2009/03/hpricot-xml-to-hash/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
