[xml] XPath api



 Hello,

 I'm having difficulties to retrieve attribute values
using the XPath API. When using an XPath expression
like //*/@foo, the resulting xmlXPathObjectPtr is
a Node Set with 0 nodes. Not espacially useful.
Using string(//*/@foo), i get an empty string.
 You'll find my code below - it's really basic.
I've browsed the docs and list archives but didn't
find anything. 

 Thanks for any help

        Fabrice

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

int main(int argc, char** argv) {
  xmlDocPtr doc;
  xmlXPathCompExprPtr xpath;
  xmlXPathObjectPtr res;
  xmlXPathContextPtr xctxt;
  
  doc = xmlParseFile(BAD_CAST "test.xml");
  if (doc != NULL) {
     fprintf(stderr, "testing xpath expr\n");
     xpath = xmlXPathCompile(BAD_CAST argv[1]);
     xctxt = xmlXPathNewContext (doc);
     res = xmlXPathCompiledEval (xpath, xctxt);
     if (res != NULL) {
       xmlXPathDebugDumpObject(stderr, res, 10);
       xmlXPathFreeObject(res);
     }
     xmlFreeDoc(doc);
  }
}

-- 
Fabrice Desré - France Telecom R&D/DTL/MSV
Tel: +(33) 2 96 05 31 43
Fax: +(33) 2 96 05 32 86



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