in reply to trying to use XML::DOM::Lite
jim:
You are right that the documentation out there is a bit tough. That being said, though, here's my first XML::DOM::Lite snipper ever ;-)
use warnings; use strict; use Data::Dumper; use XML::DOM::Lite qw( Parser XPath ); my $doc = Parser->parseFile( 'test.xml' ); my $node = $doc->selectSingleNode('quotelist/quotation[@id="q5"]/sourc +e'); print $node->firstChild()->nodeValue();
This uses your XPath query (minus the @) and gets the text from 'Node' object. (See the documentation for more info on what you can do with node object.)
BTW - I used the output from the 'Data::Dumper' to confirm that the 'Thomas Jefferson' was in the output, and with that I knew the XPath was correct.
The tricky part is realising that nodes can have multiple children (apparently!)
Anyway! Hope that get things off to a good start for you!
Kurt
PS: Happy Birthday Canada!!
Updated code for requested output.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: trying to use XML::DOM::Lite
by jim_neophyte (Sexton) on Jul 06, 2007 at 15:01 UTC | |
by jim_neophyte (Sexton) on Jul 09, 2007 at 16:01 UTC |