Re: [xml] handling xpath error - libxml



 
On 1/28/08, Stefan Behnel <stefan_ml behnel de> wrote:
Hi,

Senthil Nathan wrote:
> I would like to how to handle the xpath error gracefully when I use the
> libxml api,
> xmlXPathEvalExpression(path, xpathCtx).
>
> If I pass a invalid path string to evaluate on the "xpathCtx", it throws the
> error as below and stops there.
> But I would like to handle that error gracefully and log it accordingly and
> proceed with my application.

What is the reason why you cannot just continue after this error? Just call
xmlXPathEvalExpression() again (with a working _expression_) and everything
should be fine.
 
In my application, when an invalid xpath string is given, during the xmlXPathEvalExpression( ),
it fails with the error and just stops there. it's not continuing further and just hangs or stops there.
So, I only need to break the application. Is there a better way to handle, in case of these xpath errors.

> So, could anyone give me ideas on doing the same? Or is it possible to check
> the xpath expr is valid or not even before
> calling the libxml api.

You can compile the _expression_.
 
So do you mean by calling
xmlXPathCompile (const xmlChar * str) and then xmlXPathCompiledEval (xmlXPathCompExprPtr comp, xmlXPathContextPtr ctx) instead of xmlXPathEvalExpression( ).
Is that right. But will it not the same error happen here and just stop there?? Could you please clarify me on this.

Stefan

Thanks
Senthil Nathan R


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]