You are asking for the first occurrence of the XPath expression; if your
XML has the a/b/c as the first node, it will return immediately. If the
path cannot be found, it will have to scan the entire XML document
before returning, and that could take even much more than 40
milliseconds, if you have a big DOM tree to navigate.
Alberto
mini thomas wrote:
Hi,
I am using xerces 3.0.1 and evaluating an XPath expression "a/b/c".
DOMNode* GetNode(DOMNode* startingNode , XMLCh* xpathStr)
{
DOMDocument *doc = m_pParser->getDocument();
DOMXPathResult* result=doc->evaluate(
xpathStr,
startingNode,
NULL,
DOMXPathResult::FIRST_ORDERED_NODE_TYPE,
NULL);
if(result)
{
DOMNode* tt = result->getNodeValue();
result->release();
return tt;
}
else
return NULL;
}
The time taken by GetNode is approximately 0 milliseconds when path a/b/c exists in the document.
But the time taken is 40 milliseconds when path a/b/c doesn't exist.
Please explain this behavior. Is there any way to reduce the time taken for XPath evaluation when the node doesn't exist?
Thanks
Mini