[xml] Default namespaces with XPath



Hi,
   I'm still learning the ropes with XML. I understand I can use XPath to access particular nodes in the DOM 
tree.
I have a xml doc. with default namespaces as below:

<?xml version="1.0" encoding="UTF-8"?>
<presence xmlns="urn:ietf:params:xml:ns:cpim-pidf"
     xmlns:im="urn:ietf:params:xml:ns:cpim-pidf:im"
     xmlns:myex="http://id.example.com/cpim-presence/";
     entity="pres:someone example com"
     xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance";
     xsi:noNamespaceSchemaLocation="schema.xsd">
  <tuple id="35bs9r">
..................<snip>..............................
</presence>

I'm using XPath functions to retrieve nodes in the following way:

ctxtPtr = xmlXPathNewContext(doc);
/* Error checks */
objPtr = xmlXPathEval("/presence/tuple", ctxtPtr);
/* Error checks */
key = xmlNodeListGetString(doc,objPtr->nodesetval->nodeTab[0]->xmlChildrenNode, 1);
printf("%s: %s\n",objPtr->nodesetval->nodeTab[0]->name, key);

But the 'nodesetval' is NULL here.

What am I doing wrong and how do I use XPath with default namespaces?

Regards
Ganesh



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