lobeydosser has asked for the wisdom of the Perl Monks concerning the following question:
How can I use the text value of nodes without also getting all of the information on child1 and child2 as well? Using the following code :<root> <node>text1 <child1>data</child1> <child2>data2</child2> </node> <node>text2 <child1>blah</child1> ..etc.. </node> </root>
I see the following output :use XML::LibXML; my $file = $ARGV[0]; print $file."\n"; &parse($file); sub parse { my $filename = shift; my $parser = XML::LibXML->new(); my $doc = $parser->parse_file("$filename"); foreach my $node ($doc->findnodes('/root/node')) { print "string value :".$node->string_value."\n"; print "to literal :".$node->to_literal."\n"; print "node name :".$node->nodeName()."\n"; } }
Ideally I would like to access just the values 'text1' and 'text2' Hope this all makes sense, thanks in advance for any answers.string value :text1 data data2 to literal :text1 data data2 node name :node string value :text2 blah blah2 to literal :text2 blah blah2 node name :node
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Mixed XML content with XML::LibXML
by ForgotPasswordAgain (Vicar) on Sep 29, 2008 at 13:58 UTC | |
|
Re: Mixed XML content with XML::LibXML
by ikegami (Patriarch) on Sep 29, 2008 at 13:53 UTC | |
by ikegami (Patriarch) on Sep 29, 2008 at 13:58 UTC | |
by lobeydosser (Novice) on Sep 29, 2008 at 14:11 UTC | |
|
Re: Mixed XML content with XML::LibXML
by CountZero (Bishop) on Sep 29, 2008 at 18:33 UTC | |
by ikegami (Patriarch) on Sep 29, 2008 at 19:29 UTC | |
by CountZero (Bishop) on Sep 29, 2008 at 19:52 UTC | |
by ikegami (Patriarch) on Sep 29, 2008 at 19:56 UTC | |
by CountZero (Bishop) on Sep 29, 2008 at 20:04 UTC |