Re: [xml] About the xmlXPathEvalExpression?

±i²M¤å said:
Hi all,
    I use the xmlXPathEvalExpression to retrieval my xml file.
    But there is one problem to confused me lots of time.

    Here is my code below this line.
   xmlXPathContextPtr xpathCtx;
    xmlXPathObjectPtr xpathObj;

    xpathCtx = xmlXPathNewContext(doc);
    if(xpathCtx == NULL) {
      fprintf(stderr,"Error: unable to create new XPath context\n");

    xpathObj = xmlXPathEvalExpression((xmlChar *) "//EncryptedKey", xpathCtx);
    if(xpathObj == NULL) {
       fprintf(stderr,"Error: unable to evaluate xpath expression \"%s\"\n");

    printf("nodeset number : %d\n", xpathObj->nodesetval->nodeNr);

    Here is my xml file content below this line.
<EncryptedKey Id="EK_EncKeyA" xmlns="";>
the response is : "nodeset number : 0"
I want to get the "EncryptedKey" node, but the nodeset seems to get nothing.
I have been confused for three days.
I don't know what's wrong with my code.
I use libxml2 of 2.6.12.
Can anyone to tell me what's the problem of my code? Thanks very much.

I was hoping someone else would reply to your mail with a clear, detailled
suggestion how to fix it.  Since there has been no other reply, I can only
suggest that your problem is because of the new default namespace declared on
the element.  Your query does not include the details of the namespace,
therefore the element is not found.  You might try to search the mailing list
archives, as there have been several posts in the past on the general subject
of namespaces on XPath queries.



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