You are viewing a plain text version of this content. The canonical link for it is here.
Posted to c-dev@xerces.apache.org by Aniruddha Shevade <as...@actuate.com> on 2002/04/12 00:17:18 UTC

Performance comparison - getElementsByTagName and GetChildNodes()

Hello 
   After having parsed the xml, I want to find a particular element. I have
two approaches

1) The Most obvious is to call getElementsByTagName.  
2) USe getChildNodes and iterate over the list, and compare the node names.
   My question is does getElementByTagName internally do the same thing , as
iterating the entire DOM tree and comparing node names ?
Or does it use any sort of indexing ? In other words would
getElementsByTagName be a better choice ?

   Any help is appreciated.

thanks
-Aniruddha


Re: Performance comparison - getElementsByTagName and GetChildNodes()

Posted by Fredrick Paul Eisele <ph...@netarx.com>.
Erik Rydgren wrote:

>The getElementsByTagName method does iterate over the whole tree, comparing
>tagName with node name and in DOM2 also compares with the namespace URI. You
>do not gain anything in performance by using getElementsByTagName. But you
>do not loose any either. Then why invent the wheel again?
>
>If you are on a hunt for a specific childNode (just one matches) then use
>getElementById instead. Tag the childNode with an ID attribute and use that
>for lookups. This function is hashed to the extreme and is blazingly fast.
>
>Regards
>
Before useing getElementById, don't forget to set the attribute type to ID.
Setting the name of the attribute to id does not do it.
You either need to set it via a DTD/Xschema or use the
void XMLAttDef::setType ( ID = 1 )
method.



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


RE: Performance comparison - getElementsByTagName and GetChildNodes()

Posted by Erik Rydgren <er...@mandarinen.se>.
The getElementsByTagName method does iterate over the whole tree, comparing
tagName with node name and in DOM2 also compares with the namespace URI. You
do not gain anything in performance by using getElementsByTagName. But you
do not loose any either. Then why invent the wheel again?

If you are on a hunt for a specific childNode (just one matches) then use
getElementById instead. Tag the childNode with an ID attribute and use that
for lookups. This function is hashed to the extreme and is blazingly fast.

Regards

Erik Rydgren
Mandarinen systems AB
Sweden

-----Original Message-----
From: Aniruddha Shevade [mailto:ashevade@actuate.com]
Sent: den 12 april 2002 00:17
To: xerces-c-dev@xml.apache.org
Subject: Performance comparison - getElementsByTagName and GetChildNodes()


Hello
   After having parsed the xml, I want to find a particular element. I have
two approaches
1) The Most obvious is to call getElementsByTagName.
2) USe getChildNodes and iterate over the list, and compare the node names.
   My question is does getElementByTagName internally do the same thing , as
iterating the entire DOM tree and comparing node names ?
Or does it use any sort of indexing ? In other words would
getElementsByTagName be a better choice ?
   Any help is appreciated.
thanks
-Aniruddha


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