Re: [xml] Load Xml file issue.

On Wed, Oct 22, 2008 at 10:35:59AM +1100, Alistair Leslie-Hughes wrote:

Using the Attached file, and the below code, xmlXPathNodeSetGetLength is  
always returning 0.

doc = xmlReadFile("/tmp/AttrTest.xml", NULL, 0);
xmlXPathContextPtr ctxt = xmlXPathNewContext(doc);
xmlXPathObjectPtr pReturn = xmlXPathEval( (xmlChar*)"/string", ctxt);
int l = xmlXPathNodeSetGetLength(pReturn->nodesetval);
(omitted error checks and cleanup)

Can some tell me what is wrong?

  The usual classical error about XPath queries for namespaced elements
or attribute.

  You must use /xxx:string and define the prefix xxx in the XPath
context. See the XPath spec about why this doesn't work 
  google("libxml2 XPath default namespace")
gives an hint of how many time people fell for this


Daniel Veillard      | libxml Gnome XML XSLT toolkit
daniel veillard com  | Rpmfind RPM search engine | virtualization library

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