"Bjorn Hermans" <[EMAIL PROTECTED]> writes:

> In order to correctly test for, and retrieve, a node's attributes, I
> figured it would make sense to first use "hasAttributes()" to check
> if the node has any attributes at all. However, when I call the
> "hasAttributes" function on a DOM_Node, my program dies with the
> error "Can't locate auto/XML/Xerces/DOM_Element/hasAttribut.al in
> @INC ..."  (and no: I did not misspell the call to
> "hasAttributes()").

Hi Bjorn,

As far as I can tell there is no method hasAttributes(), where did you
find it documented?

> I then reckoned that I could (as a hack around this problem) just call
> the "getAttributes" attributes function, and only try to retrieve the
> node's attributes if this delivers a defined value to me (as in: "if
> (defined($node->getAttributes())) { ...").
> However, this doesn't work quite as expected too. It works fine for some
> nodes (e.g. nodes of the type ELEMENT_NODE), but the program core dumps
> on other node types (the node on which the program crashes is of a
> "TEXT_NODE" type - could it be that that has something to do with the
> problems?). If I instruct the program to print the results of the call
> to getAttributes (via "$node->getAttributes()") to screen, I see that
> the result of this call for the node on which the program crashes is
> "XML::Xerces::DOM_NamedNodeMap=HASH(0x84a5e1c)" (which looks okay to
> me). However, if I then try to get the number of attributes (via
> "$node->getAttributes()->getLength()") the program dumps a core.

Here's from the documentation:

  Gets a NamedNodeMap containing the attributes of this node (if it is
  an Element) or null otherwise.

Only elements can have attributes. 

I would consider this a failing of the Perl API, getAttributes()
should return undef if Xerces-C returns NULL. I'll put this on the
TODO list.

In the meantime, check the node type, and only call it for elements.

Thanks for finding this,
jas.

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

Reply via email to