You are viewing a plain text version of this content. The canonical link for it is here.
Posted to p-dev@xerces.apache.org by Bjorn Hermans <bj...@e-cube.nl> on 2002/03/21 10:25:37 UTC

Problem with getting attributes of a node

Hi,

I'm writing a program, and in this program I would like to find out if a
node has attributes (and if so: which?).
However, I'm running into two strange problems. 

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()").

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.


What is going wrong? Is this a bug in Xerces-P?
I'm running Xerces-C and Xerces-P version 1.5.2 on a RedHat 6.2 machine.
The Perl version is 5.6.1.

Regards,

Bjorn Hermans.


---------------------------------------------------------------------
To unsubscribe, e-mail: xerces-p-dev-unsubscribe@xml.apache.org
For additional commands, e-mail: xerces-p-dev-help@xml.apache.org


Re: Problem with getting attributes of a node

Posted by "Jason E. Stewart" <ja...@openinformatics.com>.
"Jason E. Stewart" <ja...@openinformatics.com> writes:

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

I cannot reproduce this in XML::Xerces-1.7:

  DB<15> x $node_list[5]->getChildNodes->item(0)
0  XML::Xerces::DOM_Text=HASH(0x105ba7ac)
     empty hash
  DB<16> x $node_list[5]->getChildNodes->item(0)->getAttributes
0  undef

It appears that the problem was fixed in Xerces-C.
jas.

---------------------------------------------------------------------
To unsubscribe, e-mail: xerces-p-dev-unsubscribe@xml.apache.org
For additional commands, e-mail: xerces-p-dev-help@xml.apache.org


Re: Problem with getting attributes of a node

Posted by "Jason E. Stewart" <ja...@openinformatics.com>.
"Steven N. Hirsch" <hi...@btv.ibm.com> writes:

> On 21 Mar 2002, Jason E. Stewart wrote:
> 
> > "Bjorn Hermans" <bj...@e-cube.nl> 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?
> 
> Interestingly enough, the Xerces-C lib v5.2 does not support 
> hasAttribute() under the IDOM interface.  Just tripped over this 
> yesterday!  Jason, do you know if it's been added to the newer releases?

It's in 1.7, but not before.
jas.

---------------------------------------------------------------------
To unsubscribe, e-mail: xerces-p-dev-unsubscribe@xml.apache.org
For additional commands, e-mail: xerces-p-dev-help@xml.apache.org


Re: Problem with getting attributes of a node

Posted by "Steven N. Hirsch" <hi...@btv.ibm.com>.
On 21 Mar 2002, Jason E. Stewart wrote:

> "Bjorn Hermans" <bj...@e-cube.nl> 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?

Interestingly enough, the Xerces-C lib v5.2 does not support 
hasAttribute() under the IDOM interface.  Just tripped over this 
yesterday!  Jason, do you know if it's been added to the newer releases?

Steve

-- 
----------------------------------------------------------------
Steven N. Hirsch       tie-line: 446-6557     ext: 802-769-6557

Staff Engineer                     Methodology Integration Team
ASIC Product Development           IBM Microelectronics
----------------------------------------------------------------


---------------------------------------------------------------------
To unsubscribe, e-mail: xerces-p-dev-unsubscribe@xml.apache.org
For additional commands, e-mail: xerces-p-dev-help@xml.apache.org


Re: Problem with getting attributes of a node

Posted by "Jason E. Stewart" <ja...@openinformatics.com>.
"Bjorn Hermans" <bj...@e-cube.nl> writes:

> > As far as I can tell there is no method hasAttributes(), 
> > where did you find it documented?
> 
> It's in the Xerces-C API documentation
> (http://xml.apache.org/xerces-c/apiDocs/class_DOM_Element.html#a19).
> Hmmm, could it be then that this method is in Xerces-C but has not been
> made available in Xerces-P?

As far as I can see this is something new for Xerces-C-1.7 and so you
won't find it in the XML::Xerces Perl API yet, since I don't have a
release of 1.7.

jas.

---------------------------------------------------------------------
To unsubscribe, e-mail: xerces-p-dev-unsubscribe@xml.apache.org
For additional commands, e-mail: xerces-p-dev-help@xml.apache.org


RE: Problem with getting attributes of a node

Posted by Bjorn Hermans <bj...@e-cube.nl>.
> "Bjorn Hermans" <bj...@e-cube.nl> 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?

It's in the Xerces-C API documentation
(http://xml.apache.org/xerces-c/apiDocs/class_DOM_Element.html#a19).
Hmmm, could it be then that this method is in Xerces-C but has not been
made available in Xerces-P?
 
[...]
> 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. 

This was indeed what I expected to happen.

> I'll put this on the TODO list.

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

Yes, I'd already added this check to my code and it works fine now.

> Thanks for finding this,

Thank you for your quick reply.

Regards,
Bjorn Hermans.




---------------------------------------------------------------------
To unsubscribe, e-mail: xerces-p-dev-unsubscribe@xml.apache.org
For additional commands, e-mail: xerces-p-dev-help@xml.apache.org


Re: Problem with getting attributes of a node

Posted by "Jason E. Stewart" <ja...@openinformatics.com>.
"Bjorn Hermans" <bj...@e-cube.nl> 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: xerces-p-dev-unsubscribe@xml.apache.org
For additional commands, e-mail: xerces-p-dev-help@xml.apache.org