Hpricot and XML

A

Alex Young

Hi all,

I've got a little XML parsing problem, and I'd like to use hpricot to
use it. The following script:

require 'rubygems'
require 'hpricot'

xml = <<-XML
<gnc:account version="2.0.0">
<act:name>Child Account</act:name>
<act:id type="guid">4ba14634e8e52775af401ff8ae797316</act:id>
<act:type>BANK</act:type>
<act:commodity>
<cmdty:space>ISO4217</cmdty:space>
<cmdty:id>GBP</cmdty:id>
</act:commodity>
<act:commodity-scu>100</act:commodity-scu>
<act:parent type="guid">e83af2b8702f9bfbde73bd723216fe4f</act:parent>
</gnc:account>
XML

doc = Hpricot.XML(xml)
puts doc.at("act:id").inner_html
puts doc.at("act:name").inner_html
puts doc.at("act:type").inner_html
puts doc.at("act:parent").inner_html

produces the following output:

$ ruby test_hpricot.rb
4ba14634e8e52775af401ff8ae797316
Child Account
BANK
test_hpricot.rb:22: undefined method `inner_html' for nil:NilClass
(NoMethodError)

I *think* the exception is being caused by hpricot parsing the :parent
as a pseudoclass. Any ideas as to how I could make that not happen, or
otherwise make the last line of the script correctly display the guid in
question?
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,780
Messages
2,569,611
Members
45,274
Latest member
JessMcMast

Latest Threads

Top