in reply to Re: Mixed XML content with XML::LibXML
in thread Mixed XML content with XML::LibXML

Then again, I think that would return four nodes for
<root> <node> text1a <child1>data</child1> <child2>data2</child2> text1b </node> <node> text2a <child1>blah</child1> text2b </node> </root>

If that's a problem, find /root/node elements, then for each of those elements, find child::text().

Sorry, I don't have XML::LibXML here to test.

Replies are listed 'Best First'.
Re^3: Mixed XML content with XML::LibXML
by lobeydosser (Novice) on Sep 29, 2008 at 14:11 UTC
    Thanks guys , managed to get it working now.
    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 "textval :".$node->findnodes('./text()')->to_literal."\n"; } }
    This does the trick. The particular data set I'm using should never have more than one text value mixed in with the child nodes.