How to best extract Ruby strings from REXML::Text instances?

K

Kenneth McDonald

REXML is a great package and is making it very easy for me to extract
data from web pages. However, I'm having trouble with extracting a file
string value from text nodes. My understanding from reading the API doc
is that saying something like

p a_textnode.value

should print out the string value of the textnode with special character
entities back-substituted, eg. with " " put in place of " ".
However, I'm getting the XML-style value, i.e. I'm getting something like

 15.16 

printed to the terminal, special character entities aren't being
substituted for.


Am I misinterpreting what .value does? Is there a better or other way to
do this?


Thanks,
Ken

P.S. Can anyone recommend a good XPath quick reference or summary?
 
R

Robert Klemme

2007/8/26 said:
REXML is a great package and is making it very easy for me to extract
data from web pages. However, I'm having trouble with extracting a file
string value from text nodes. My understanding from reading the API doc
is that saying something like

p a_textnode.value

I think you want "element.text".

irb(main):008:0> t=REXML::Document.new("<foo>bar</foo>")
=> <UNDEFINED> ... </>
irb(main):009:0> t.root.text
=> "bar"
irb(main):010:0> t.root.text.class
=> String
should print out the string value of the textnode with special character
entities back-substituted, eg. with " " put in place of "&nbsp;".
However, I'm getting the XML-style value, i.e. I'm getting something like

&nbsp;15.16&nbsp;

printed to the terminal, special character entities aren't being
substituted for.


Am I misinterpreting what .value does? Is there a better or other way to
do this?


Thanks,
Ken

P.S. Can anyone recommend a good XPath quick reference or summary?

I use this frequently:
http://www.w3schools.com/xpath/

and sometimes this:
http://www.zvon.org/xxl/XPathTutorial/General/examples.html

Kind regards

robert
 

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,744
Messages
2,569,482
Members
44,901
Latest member
Noble71S45

Latest Threads

Top