Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl: the Markov chain saw
 
PerlMonks  

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?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others rifling through the Monastery: (3)
As of 2021-02-24 17:44 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found

    Notices?