Hi Martin, Thanks for the quick response. Its all starting to make sense now. Best Regards Alistair Leslie-Hughes > Date: Fri, 18 Apr 2008 12:32:34 +0100 > From: gzlist googlemail com > To: leslie_alistair hotmail com > Subject: Re: [xml] Namespace Query Issue > CC: xml gnome org > > On 18/04/2008, Alistair Leslie-Hughes <leslie_alistair hotmail com> wrote: > > Hi, > > > > When use xmlXPathEval with the query "/root/WEB:Site" on the following xml > > > > <?xml version=\"1.0\"?> > > <root xmlns:WEB='http://www.winehq.org'> > > <WEB:Site version=\"1.0\" /> > > </root> > > > > I get the following error > > XPath error : Undefined namespace prefix > > xmlXPathEval: evaluation failed > > > > Using the same xml and query in MSXML it works. > > > > Can someone explain what I am doing wrong? > > > > Best Regards > > Alistair Leslie-Hughes > > You need to register the namespace prefix/uri pair on the xpath context. > > See: > http://xmlsoft.org/html/libxml-xpathInternals.html#xmlXPathRegisterNs > > Some example xpath code: > http://xmlsoft.org/examples/xpath1.c > > Or python version, which is brief enough for email: > >>> import libxml2 > >>> doc = libxml2.parseDoc("""<?xml version="1.0"?> > ... <root xmlns:WEB='http://www.winehq.org'> > ... <WEB:Site version="1.0"/> > ... </root>""") > >>> ctx = doc.xpathNewContext() > >>> ctx.xpathRegisterNs("WEB", "http://www.winehq.org") > 0 > >>> ctx.xpathEval("count(//WEB:*)") > 1.0 > > This one really needs to go on an FAQ thingy really. > > Martin at CarPoint.com.au It's simple! Sell your car for just $30 |