[xml] Register default namespace prefix to the xpath context


Are there any way to register a zero length namespace prefix
(default namespace) to the xpath context?

I want to register a default namespace prefix for xpath context so
that xpath expression can be specified simply for the documents which
contains default namespace. But libxml2 seems not register nor lookup
default namespace prefix.

I wrote following test program.

#include <stdio.h>
#include <libxml/parser.h>
#include <libxml/tree.h>
#include <libxml/xpath.h>

int main (int argc, char **argv)
  xmlDocPtr doc;
  xmlXPathContextPtr ctxt;
  xmlXPathObjectPtr result;

  doc = xmlParseDoc ("<foo xmlns=\"http://bar/\"/>");
  ctxt = xmlXPathNewContext (doc);
  xmlXPathRegisterNs (ctxt, "", "http://bar/";);
  result = xmlXPathEval ("/foo", ctxt);
  fprintf (stdout, "Nodes = %d\n", result->nodesetval->nodeNr);

I expected it returns 'Nodes = 1' but it returns 'Nodes = 0'.

I'm sorry if this is a FAQ or known problem.
Yuuichi Teranishi <teranisi gohome org>
PGP 5.0i Public Key: http://www.gohome.org/pgp5/teranisi.key
"For tomorrow may rain, so I'll follow the sun."

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