[xml] XPath and namespaces



Hallo,
I can ask how to use XPath with a XML document which is using
namespaces. I need process "/configuration/@version" expression
on the follow document.

  <?xml version="1.0"?>
  <configuration xmlns="http://www.liberouter.org"; version="1.2">
    ...
  </configuration>

So I tried set namespaces to xmlXpathContext, bud it still
not works. I mean something like:

  context->namespaces = xmlGetNsList(Document, xmlDocGetRootElement(Document));
  context->nsNr = 0;
  if (context->namespaces != NULL){
    while (context->namespaces[context->nsNr] != NULL)
      context->nsNr++;
  }

I read at http://mail.gnome.org/archives/xml/2002-December/msg00186.html
that it can be solbed by xmlXPathRegisterNs(). So I tried

  xmlXPathRegisterNs(context, NULL, "http://www.liberouter.org";);
or
  xmlXPathRegisterNs(context, "", "http://www.liberouter.org";);

(because I don't use prefix), bud it still not works. What am I doing
wrong? If I use prefix in XPath expression, it seems to wokr fine.


Thank you

Have a nice day

-petrn

-- 

Petr Novak, Liberouter Project (www.liberouter.org)
E-mail: novak merlot ics muni cz




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