You are viewing a plain text version of this content. The canonical link for it is here.
Posted to c-users@xalan.apache.org by al...@cwazy.co.uk on 2004/09/29 09:37:11 UTC

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.


Re: what should happen when path does not exsist

Posted by al...@cwazy.co.uk.
Thanks for the reply!
The node is selected - it exsists, but the "evaluate" later on is the
function I ask about, It returns the XObjectPtr, which is not null but
still has no data...

The xml is as simple as:
<Node>
  <Son>SonVal</Son>
</Node>

And I select Node, and the query Son's value - and need to know is it
there or not.

Thanks again,
Alice

> 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.
>
>
>
>
>
>
>
>
>
> alice@cwazy.co.uk
> 09/29/2004 03:37 AM
> Please respond to
> xalan-c-users
>
>
> To
> xalan-c-users@xml.apache.org
> 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.
>
>
>



Re: what should happen when path does not exsist

Posted by Matthew Hoyt <mh...@ca.ibm.com>.
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.





 



alice@cwazy.co.uk 
09/29/2004 03:37 AM
Please respond to
xalan-c-users


To
xalan-c-users@xml.apache.org
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.



Re: what should happen when path does not exsist

Posted by da...@us.ibm.com.
> 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.

You will get an empty node-set, not an exception.

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

If you are sure your expression evaluates to a node-set, call the 
node-set() function on the resulting XObject and get its length.

Dave