Re: [xml] handling xpath error - libxml



Hi,

Senthil Nathan wrote:
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.

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///*[ check='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);


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



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