mirror of
https://github.com/gnustep/libs-base.git
synced 2025-04-22 16:33:29 +00:00
Added method to register namespaces with XPath
git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/base/trunk@25874 72102866-910b-0410-8b05-ffd578937521
This commit is contained in:
parent
0727937d01
commit
5c6c74539f
3 changed files with 41 additions and 0 deletions
|
@ -1,3 +1,10 @@
|
|||
2008-01-05 Nicola Pero <nicola.pero@meta-innovation.com>
|
||||
|
||||
* Source/Additions/GSXML.m ([GSXPathContext
|
||||
-registerNamespaceWithPrefix:href:]): Added new method to support
|
||||
namespaces in XPath expressions.
|
||||
* Headers/Additions/GNUstepBase/GSXML.h: Same.
|
||||
|
||||
2008-01-05 Richard Frith-Macdonald <rfm@gnu.org>
|
||||
|
||||
* config/pathtls.m4: fixup form mingw32
|
||||
|
|
|
@ -363,6 +363,20 @@ extern "C" {
|
|||
* GSXPathString *result = [p evaluateExpression: @"string(/body/text())"];
|
||||
* NSLog (@"Got %@", [result stringValue]);
|
||||
*
|
||||
* If the XML document contains namespaces, you first need to register them
|
||||
* with the parser by using registerNamespaceWithPrefix:href:, as in:
|
||||
*
|
||||
* GSXPathContext *p = [[GSXPathContext alloc] initWithDocument: document];
|
||||
* if ([p registerNamespaceWithPrefix: @"a" href="http://www.gnustep.org/demo"] == NO)
|
||||
* {
|
||||
* // Error registering namespace, do something about it.
|
||||
* }
|
||||
*
|
||||
* and then you can use the namespace prefix in your expressions, as in
|
||||
*
|
||||
* GSXPathString *result = [p evaluateExpression: @"string(/a:body/text())"];
|
||||
* NSLog (@"Got %@", [result stringValue]);
|
||||
*
|
||||
*/
|
||||
@interface GSXPathContext : NSObject
|
||||
{
|
||||
|
@ -371,6 +385,12 @@ extern "C" {
|
|||
}
|
||||
- (id) initWithDocument: (GSXMLDocument*)d;
|
||||
- (GSXPathObject*) evaluateExpression: (NSString*)XPathExpression;
|
||||
|
||||
/*
|
||||
* Registers a new namespace. Return YES if succesful, NO if not.
|
||||
*/
|
||||
- (BOOL) registerNamespaceWithPrefix: (NSString *)prefix
|
||||
href: (NSString *)href;
|
||||
@end
|
||||
|
||||
/** XPath queries return a GSXPathObject. GSXPathObject in itself is
|
||||
|
|
|
@ -70,6 +70,7 @@
|
|||
#include <libxml/HTMLparser.h>
|
||||
#include <libxml/xmlmemory.h>
|
||||
#include <libxml/xpath.h>
|
||||
#include <libxml/xpathInternals.h>
|
||||
|
||||
#ifdef HAVE_LIBXSLT
|
||||
#include <libxslt/xslt.h>
|
||||
|
@ -3753,6 +3754,19 @@ fatalErrorFunction(void *ctx, const unsigned char *msg, ...)
|
|||
return result;
|
||||
}
|
||||
|
||||
- (BOOL) registerNamespaceWithPrefix: (NSString *)prefix
|
||||
href: (NSString *)href
|
||||
{
|
||||
if (xmlXPathRegisterNs (_lib, UTF8STRING(prefix), UTF8STRING(href)) != 0)
|
||||
{
|
||||
return NO;
|
||||
}
|
||||
else
|
||||
{
|
||||
return YES;
|
||||
}
|
||||
}
|
||||
|
||||
- (void) dealloc
|
||||
{
|
||||
xmlXPathFreeContext (_lib);
|
||||
|
|
Loading…
Reference in a new issue