http://qs1969.pair.com?node_id=62815


in reply to XML::DOM::Parser

I think you're trying to print the wrong Text elements. There appears to be several Text element children of the root node, these are not what you want to print.

The below XML is what I tested:

<?xml version="1.0"?> <root> <something>hello</something> <something>world</something> </root>

And parsed it with the script:

#!/usr/bin/perl -w use strict; use XML::DOM; my $p = XML::DOM::Parser->new(); my $doc = $p->parsefile('test.xml'); my $root = $doc->getFirstChild(); foreach my $node($root->getChildNodes) { if($node->getNodeType == ELEMENT_NODE) { for my $child($node->getChildNodes) { if($child->getNodeType == TEXT_NODE) { print $child->getData, "\n"; } } } }
The actual Text nodes you want are contained within Element children of the root node. I don't think you're traversing deep enough into the DOM tree.