On 1/28/08, Senthil Nathan <[EMAIL PROTECTED]> wrote:
>
>
>
> On 1/28/08, Stefan Behnel <[EMAIL PROTECTED]> wrote:
>
> > Hi,
> >
> > Senthil Nathan wrote:
> > > On 1/28/08, Stefan Behnel <[EMAIL PROTECTED]> 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.
> >
> > Ah, so it hangs *in* the eval call and does not return? I've never seen
> > that
> > before. And it definitely works for me in lxml (libxml2 2.6.31):
> >
> > >>> import lxml.etree as et
> > >>> root = et.XML("<root/>")
> > >>> root.xpath("/roottag///[EMAIL PROTECTED]'1']")
> > Traceback (most recent call last):
> > [...]
> > lxml.etree.XPathEvalError: Invalid expression
> > >>>
> >
> > That's basically using this code:
> >
> > xpathCtxt.node = some_node;
> > xpathObj = xmlXPathEvalExpression(c_path, xpathCtxt);
>
>
> I'm using the version 2.6.30 of libxml2
> #define PACKAGE "libxml2"
> #define VERSION "2.6.30"
>
> The same way I also do it. But its only with my application which has
> several threads, and when I give an invalid path, just hangs. Also the CPU
> load is around 92% and keeps increasing further.
>
> xmlXPathCtxPtr xpathCtx = xmlXPathNewContext(docTree);
>
> xpathObj = xmlXPathEvalExpression(path, xpathCtx);
>
> return(xpathObj->nodesetval);
>
> Should I need to disable some flags. Because, in case of invalid expr, its
> not returning from xmlXPathEvalExpression( ). If it's returns null, I can do
> further processing. Or am I not handling it properly. I guess so.
>
> > Could you supply the libxml2 version you are using and some example code
> > that
> > shows the problem? Does your machine show high CPU load while it hangs?
> > (i.e.
> > does it do something?)
> >
> > Stefan
> >
>
>
I could now handle the invalid xpath error, if I use the foll. api's
xmlXPathCompExprPtr xpathComp = xmlXPathCompile(path);
if(xpathComp)
{
xpathObj = xmlXPathCompiledEval(xpathComp, xpathCtx);
return(xpathObj->nodesetval);
}
else
{
printf("OTAccess::OTxmlXPathEvalExpression Invalid Expression\n");
return 0;
}
Now it doesn't dump core and the error is handled properly.
But Is it possible get that error message in a buffer string using the
errno, during runtime.
"XPath error : Invalid expression
/roottag///,[EMAIL PROTECTED]'1']"
Please help me on this.
Thanks
Senthil Nathan R
_______________________________________________
xml mailing list, project page http://xmlsoft.org/
[email protected]
http://mail.gnome.org/mailman/listinfo/xml