Beefy Boxes and Bandwidth Generously Provided by pair Networks
go ahead... be a heretic

Re: XML::DOM::Parser

by rpc (Monk)
on Mar 08, 2001 at 00:17 UTC ( #62815=note: print w/replies, xml ) Need Help??

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.

Log In?

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://62815]
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others rifling through the Monastery: (2)
As of 2023-02-05 13:16 GMT
Find Nodes?
    Voting Booth?
    I prefer not to run the latest version of Perl because:

    Results (31 votes). Check out past polls.