<?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>Sat, 16 Jul 2011 14:57:15 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.2.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>tov</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>
<p>[sourcecode language='ruby']<br />
require &#8216;rubygems&#8217;<br />
require &#8216;hpricot&#8217;<br />
require &#8216;pp&#8217;</p>
<p>text = <<eof</p>
<payment>
		<vat></p>
<pay_vat>0</pay_vat>
			<vat_id/><br />
		</vat><br />
		<creditcard><br />
			<type>master</type><br />
			<holder>Franz Fluchsfinger</holder><br />
			<company/><br />
			<no>52660xxxxxxxxxxx79</no><br />
			<kpn/><br />
			<valid_until>09/10</valid_until><br />
			<data>Just some data</data><br />
			<xml_for_demo><inner_xml>inner text</inner_xml></xml_for_demo><br />
			<signature>a5f4e2shortened4b1e523ca873837c8f1c9ea66ee1924d</signature><br />
		</creditcard>
</payment>
eof</p>
<p>xml =Hpricot.XML(text)<br />
a= xml/&#8221;creditcard/*&#8221;<br />
h={}<br />
a.each {|b|<br />
	h[b.name] = b.inner_text if b.is_a? Hpricot::Elem<br />
}<br />
pp h	</p>
<p>[/sourcecode]</p>
<p>result:</p>
<p><code><br />
ruby test.rb<br />
{"company"=&gt;"",<br />
"xml_for_demo"=&gt;"inner text",<br />
"no"=&gt;"52660xxxxxxxxxxx79",<br />
"holder"=&gt;"Franz Fluchsfinger",<br />
"signature"=&gt;"a5f4e2shortened4b1e523ca873837c8f1c9ea66ee1924d",<br />
"type"=&gt;"master",<br />
"valid_until"=&gt;"09/10",<br />
"kpn"=&gt;"",<br />
"data"=&gt;"Just some data"}<br />
</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>

