Re: [xml] Load Xml file issue.



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

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

-- 
Daniel Veillard      | libxml Gnome XML XSLT toolkit  http://xmlsoft.org/
daniel veillard com  | Rpmfind RPM search engine http://rpmfind.net/
http://veillard.com/ | virtualization library  http://libvirt.org/



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