"Pam Gage" <[EMAIL PROTECTED]> writes:

> 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?

can't find auto/XML/Xerces/... means that you have given it an object
of type XML::Xerces::DOM_Text for the $cNodes variable and you are
invoking the method item(), which Perl is attempting (and failing) to
resolve up the object hierarchy. It attempts to use the AutoLoader
(hence the item.al) but Xerces doesn't using autoloading so of course
it didn't find anything.

You usually get that message when you mis-spell a method, or in your
case you are attempting to invoke a method from the DOM_NodeList class
on an instance of the DOM_Node class. DOM_Node (nor any of it's
subclasses ) has a method item(). Your mistake appears here:

   my($cNodes) = $pNode->getChildNodes();

You are invoking getChildNodes() in a list context (because you are
surrounding the $cNodes variable in parens) and that causes the method
to return a list of DOM_Node instances *instead* of a single
DOM_NodeList instance - which is what you were expecting. This is a
Perl-specific *feature* because NodeList's are just arrays and
NamedNodeMap's are just hash tables. If you invoke it in a *scalar*
context you will get what you want:

   my $cNodes = $pNode->getChildNodes();

and your code should work. This is described in the README and on the
WWW site under the section of Perl-specific features.

> 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.

Unfortunately 1.3.3 is ancient history. I really hope that someone
will finish porting Xerces-1.7 to Windows, because then you could use
the DOM_TreeWalker code which only got fully implemented this last
release.

HTH,
jas.

---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to