in reply to XML::DOM::Parser
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:
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.#!/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"; } } } }
|
|---|