in reply to Mixed XML content with XML::LibXML

Change your query to /root/node/text()

XPath spec

Replies are listed 'Best First'.
Re^2: Mixed XML content with XML::LibXML
by ikegami (Patriarch) on Sep 29, 2008 at 13:58 UTC
    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.

      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.