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
In reply to Mixed XML content with XML::LibXML by lobeydosser
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |