Re: [xml] does libxml support namespace completely?



Hi,

hi there!
i have a question about the namespace! now i use the libxml process a xml file
with the
namespace, but it can't work well.
my xml file is:


      
              
    abcd
      


i invoke the xmlGetPath(ptr),the ptr is the node pointer to the
    ,and the returen is
    /(null):root/(null):cc/(null)dd.
    but when i invoke the xpath api to fetch the node pointer with above
    path,it return the null.
    who can tell me why? and if the libxml can't support the namespace completely.


It just happend to me too. You have to register a namespace and use this for the
xpath query to work. You can leave you document as it is.

  if((ctxt=xmlXPathNewContext(elements->doc))) {
    ctxt->node=xmlDocGetRootElement(doc);
    if(!xmlXPathRegisterNs(ctxt,"q","http://www.test.org/q-1.0/";)) {
      result=xmlXPathCompiledEval(xpath_expression,ctxt);
      xmlXPathRegisteredNsCleanup(ctxt);
    }
    xmlXPathFreeContext(ctxt);
  }

then use 'q' as the namespace in your query.

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]