Sourcecode and WordPress
Friday, March 20th, 2009At last…
I found the plugin SyntaxHilighter forWordPress (wasn’t that hard. It’s part of the WordPress FAQ) to solve my formatting problems…
At last…
I found the plugin SyntaxHilighter forWordPress (wasn’t that hard. It’s part of the WordPress FAQ) to solve my formatting problems…
Well: I nearly lost all my hairs about this. Strange that I couldn’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’s not working is the “inner_xml” part. I personally don’t need it but your mileage may vary and you may want to fix the issue (and give me a note)
require 'rubygems'
require 'hpricot'
require 'pp'
text = <<eof
<payment>
<vat>
<pay_vat>0</pay_vat>
<vat_id/>
</vat>
<creditcard>
<type>master</type>
<holder>Franz Fluchsfinger</holder>
<company/>
<no>52660xxxxxxxxxxx79</no>
<kpn/>
<valid_until>09/10</valid_until>
<data>Just some data</data>
<xml_for_demo><inner_xml>inner text</inner_xml></xml_for_demo>
<signature>a5f4e2shortened4b1e523ca873837c8f1c9ea66ee1924d</signature>
</creditcard>
</payment>
eof
xml =Hpricot.XML(text)
a= xml/"creditcard/*"
h={}
a.each {|b|
h[b.name] = b.inner_text if b.is_a? Hpricot::Elem
}
pp h
result:
[code]]czozMDE6XCINCnJ1YnkgdGVzdC5yYg0Ke1wiY29tcGFueVwiPSZndDtcIlwiLA0KXCJ4bWxfZm9yX2RlbW9cIj0mZ3Q7XCJpbm5lciB0ZXh0XCIsDXtbJiomXX0KXCJub1wiPSZndDtcIjUyNjYweHh4eHh4eHh4eHg3OVwiLA0KXCJob2xkZXJcIj0mZ3Q7XCJGcmFueiBGbHVjaHNmaW5nZXJcIiwNClwic2lnbmF0e1smKiZdfXVyZVwiPSZndDtcImE1ZjRlMnNob3J0ZW5lZDRiMWU1MjNjYTg3MzgzN2M4ZjFjOWVhNjZlZTE5MjRkXCIsDQpcInR5cGVcIj0mZ3Q7XCJtYXN7WyYqJl19dGVyXCIsDQpcInZhbGlkX3VudGlsXCI9Jmd0O1wiMDkvMTBcIiwNClwia3BuXCI9Jmd0O1wiXCIsDQpcImRhdGFcIj0mZ3Q7XCJKdXN0IHNvbWUgZGF0YXtbJiomXX1cIn0NClwiO3tbJiomXX0=[[/code]
Btw.: I found the solution partly on http://railsforum.com/viewtopic.php?id=22055