Re: [xml] xmllint and namespaces



Hi Fabrice,
Stefan Kost wrote:

 > and invoked
 > # testXPath -i share/gitk/gitkHelloUser_main.xml
 > "//control[ id="UserName"]"
 > Object is a Node Set :
 > Set contains 0 nodes


  Di you try testXPath -i share/gitk/gitkHelloUser_main.xml
"//control[ id='UserName']"
>
dumb me. okay that fixes it there.


 >
 > Finaly about "xmlXPathNewContext()", when I had been using a namespace
 > with a
 > prefix I was using
 >       ctxt->namespaces=g_new(xmlNsPtr,1);
 >       ctxt->namespaces[0]=mynamespace;
 >       ctxt->nsNr=1;
 > before using the context. Now that namespace has a "ns->prefix==NULL",
 > should I
 > still attach it or better use
 >       ctxt->namespaces=NULL;
 >       ctxt->nsNr=0;
 > It seems to make no difference. I don't use "xmlXPathRegisterNs()" as
 > there is
 > no version of it accepting a xmlNsPtr.

Okay now I use
                if(!xmlXPathRegisterNs(ctxt,elements->ns->prefix,elements->ns->href)) {
        gitk_log("  before xmlXPathCompiledEval()");
        result=xmlXPathCompiledEval(xpath_expression,ctxt);
        xmlXPathRegisteredNsCleanup(ctxt);
}

DANIEL: there is a typo in the API docs about "xmlXPathRegisteredNsCleanup()"
I guess it frees all memory allocated by previous xmlXPathRegisterNs() calls.


Stephan,

  I'm using the XPath support of libxml in lots of programs and never
had any problem. Since XPath has no notion of a default namespace, you
*MUST* bind every namespace used in your queries to a prefix, even if
you are using a default namespace declaration in the instance. Of course
this prefix can be different from the one used in your document. If you
follow these simple rules you'd be OK. I'm always using
xmlXPathRegisterNs() to add my namespace binding into the XPath engine,
and use these prefix in my expressions. Works like a charm.

You mean I can use a document *without namespaceprefixes, but with a default ns such as
<giml xmlns="http://gitk.sourceforge.net/";>
  <context/>
</giml>

and when doing a query I register a ns={prefix="q",href="http://gitk.sf.net/"} and writing my query as e.g. "//q:context"?

Stefan
--
      \|/            Stefan Kost
     <@ @>           private            business
+-oOO-(_)-OOo------------------------------------------------------ - - -  -   -
|       __  Address  Simildenstr. 5     HTWK Leipzig, Fb IMN, Postfach 300066
|      ///           04277 Leipzig      04277 Leipzig
| __  ///            Germany            Germany
| \\\///    Phone    +49341 2253538     +49341 30766101
|  \__/     EMail    st_kost gmx net    kost imn htwk-leipzig de
|           WWW      www.sonicpulse.de  www.imn.htwk-leipzig.de/~kost/about.html
===-=-=--=---=---------------------------------- - - -  -    -




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