On Tue, 26 Oct 2004 03:47:50 -0500, Nash Kabbara <>
wrote:
>This takes around 20 seconds to complete processing.
I'm not surprised ! getElementsByTagName is always slow, but it's
also inefficient here because it's having to look everywhere in the
structure to find elements to test their names. If you can improve
the search by looking for elements as children or grand-children,
rather than searching everywhere for them, then this can be a good
tweak.
XML is often incredibly powerful, but this excess power can lead to
inefficiencies if it's being used "by default" when you didn't really
need it.
> So my question is, is
>there some way where I can extract xml elements based on the element value.
Yes, XPath ! Just use "//MyElementName"
Or if MyElementName is supplied by the users, then use a [...]
predicate and the local-name() function to get the name of the
element, then compare it to the value of an element name supplied as a
parameter.
<xsl

aram name="elmName" >MyElementName</xsl

aram>
...
//*[local-name() = string($elmName)]
XQuery (and various other incarnations) will do it too, and with
better performance. However it's sometimes hard to find XQuery
features in an environment, but most will have XSLT and XPath
available.