[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: GSXPathContext examples ?
From: |
Nicola Pero |
Subject: |
Re: GSXPathContext examples ? |
Date: |
Sat, 5 Jan 2008 22:03:28 +0100 (CET) |
> Thanks Nicola, now I figured out that my code doesn't work because of
> namespaces.
>
> I tried using namespaces in the query (as in "//D:href")
> but I can't make it work. Would you have any pointer on how to deal
> with namespaces with GNUstep XPath tools ?
There is no syntax in XPath itself to declare a namespace; you have first to
use a separate API (dependent on the XML library in use) to tell the XML parser
about what mappings between prefixes and namespaces you want to use, then you
can use these prefixes in your XPath expressions.
libxml2 has this API but GSXPath was missing a wrapper method - I added it in
subversion. You should still be able to do it manually in older releases as
follows
(untested) --
if ((xmlXPathRegisterNs ([p lib], "D", "DAV:") != 0)
||(xmlXPathRegisterNs ([p lib], "ap", "http://apache.org/dav/props") != 0))
{
/* Error registering namespaces; do something about it. */
}
(then a query as in "//D:href" should work)
If you're using gnustep-base from trunk, you can try
if (![p registerNamespaceWithPrefix: @"D" href="DAV:"]
|| (![p registerNamespaceWithPrefix: @"ap"
href="http://apache.org/dav/props/"]))
{
/* Error registering namespaces; do something about it. */
}
which does exactly the same thing (I tried this one, and it works for me). :-)
Thanks