I know there's got to be a way to do this, but I am
having a dismal time trying to just print each node name
for an xml document. Can someone please help? My program
is breaking at the point marked by ***. It can't find auto?
What does this mean?
Environment: Windows NT
ActiveState v5.6.1
Xerces v1.3.3 (also from ActiveState)
Also, if someone has an example of doing a tree traversal, it
would be very helpful. I have done this many times in Java,
but cannot seem to get the Perl equivalent working. I am not
very familiar with "object oriented" Perl.
Here's my program. Any help is appreciated.
PG
--------------------
#!c:/ActiveState/bin/Perl -w
use XML::DOM;
use XML::Xerces;
$fullpath = "test.xml";
my $parser = new XML::Xerces::DOMParser;
$parser->setDoValidation(1);
$parser->parse(XML::Xerces::LocalFileInputSource->new($fullpath));
my $doc = $parser->getDocument();
# Get the root node
my $nodes = $doc->getElementsByTagName("component");
my $len = $nodes->getLength;
# Loop through children and print their children
for($i = 0; $i < $len; $i++) {
&printNode($doc, $nodes->item($i));
}
# Recursively go through the rest of the children
sub printNode {
my($local_doc) = $_[0];
my($pNode) = $_[1];
# Print data from current node
my($name) = $pNode->getNodeName();
print "Name: $name\n";
my($cNodes) = $pNode->getChildNodes();
my($clen) = $cNodes->getLength;
for($j = 0; $j < $clen; $j++) {
# *** Code breaks here. Error is:
# Can't locate auto/XML/Xerces/DOM_Text/item.al in @INC (@INC contains:
# C:/ActiveState/lib C:/ActiveState/site/lib .) at print.pl line 39
if($cNodes->item($j)->getNodeType() == $XML::Xerces::DOM_NODE::ELEMENT_NODE) {
&printNode($local_doc, $cNodes->item($j));
}
}
}
exit(0);
