Hi,

According to the documentation:

XPathEvaluator::selectSingleNode  will not throw an exception, but return 0 if no nodes are selected.

From the documentation (http://xml.apache.org/xalan-c/apidocs/classXPathEvaluator.html#a2):
"If the _expression_ doesn't select a node, 0 is returned. If it selects more than one node, only the first is returned."

-Matt.









[EMAIL PROTECTED]

09/29/2004 03:37 AM

Please respond to
xalan-c-users

To
[email protected]
cc
Subject
what should happen when path does not exsist





Hi all.

I have a bit of simple code using xalan to get a certain node value, but
in the case the node does not exsist I expect it to throw an exception,
which doesn't happen.
This is a segment of the code:


....
try
                {
                                 // OK, let's find the context node...
                                 XalanNode* const                 theContextNode =
                                                  theEvaluator.selectSingleNode(
                                                  theDOMSupport,
                                                  &docWrapper,
                                                  XalanDOMString(szContext).c_str(), prefixResolver
                                                  );

                                 if (theContextNode)
                                 {
                                                  // OK, let's evaluate the _expression_...
                                                  const XObjectPtr                 theResult(
                                                                   theEvaluator.evaluate(
                                                                   theDOMSupport,
                                                                   theContextNode,
                                                                   XalanDOMString(xpathXpr).c_str(),
                                                                   prefixResolver
                                                                   ));
                                                  if(!theResult.null()){
                            return theResult;
                                                  }
                                 }
                }
                catch(...)
                {
         // doesn't get here...
                }

...

When I use ->str on the result object I get an empty string.
How can I know the path does not exist?

Thanks alot.
Alice.


Reply via email to