From 68532a139fc2fce77adc7395c1772fcf21d86b65 Mon Sep 17 00:00:00 2001 From: helge Date: Sat, 30 Jul 2005 18:44:32 +0000 Subject: [PATCH] added more KVC support to DOM git-svn-id: http://svn.opengroupware.org/SOPE/trunk@949 e4a50df8-12e2-0310-a44c-efbce7f8a7e3 --- sope-xml/DOM/ChangeLog | 6 +++++- sope-xml/DOM/DOMElement.m | 20 +++++++++++++++++++- sope-xml/DOM/README | 3 +++ sope-xml/DOM/Version | 2 +- 4 files changed, 28 insertions(+), 3 deletions(-) diff --git a/sope-xml/DOM/ChangeLog b/sope-xml/DOM/ChangeLog index d9800e7c..7daa4e90 100644 --- a/sope-xml/DOM/ChangeLog +++ b/sope-xml/DOM/ChangeLog @@ -1,6 +1,10 @@ 2005-07-30 Helge Hess - * v.4.5.17 + * DOMElement.m: evaluate KVC keys starting with a slash '/' as query + path expressions (by stripping of the slash!), return an attribute + node for keys starting with '@' (v4.5.18) + + * v4.5.17 * DOMDocument.m: evaluate KVC keys starting with a slash '/' as query path expressions diff --git a/sope-xml/DOM/DOMElement.m b/sope-xml/DOM/DOMElement.m index 256901c0..d16930c5 100644 --- a/sope-xml/DOM/DOMElement.m +++ b/sope-xml/DOM/DOMElement.m @@ -24,8 +24,10 @@ #include #include #include +#include "DOMNode+QueryPath.h" #include "common.h" + @interface _DOMElementAttrNamedNodeMap : NSObject < DOMNamedNodeMap > { NGDOMElement *element; /* non-retained */ @@ -520,8 +522,24 @@ static NSNull *null = nil; return [self childNodes]; } +/* key/value coding */ + +- (id)valueForKey:(NSString *)_key { + if ([_key hasPrefix:@"/"]) + return [self lookupQueryPath:[_key substringFromIndex:1]]; + + if ([_key hasPrefix:@"@"]) { + return [[self attributes] namedItem:[_key substringFromIndex:1] + namespaceURI:@"*"]; + } + + return [super valueForKey:_key]; +} + @end /* NGDOMElement */ + + @implementation _DOMElementAttrNamedNodeMap - (id)initWithElement:(id)_element { @@ -768,7 +786,7 @@ static NSString *_XNSLocalName(NSString *_name) { [ms appendString:@" attributes:\n"]; e = [self objectEnumerator]; - while ((attr = [e nextObject])) { + while ((attr = [e nextObject]) != nil) { [ms appendString:[attr description]]; [ms appendString:@"\n"]; } diff --git a/sope-xml/DOM/README b/sope-xml/DOM/README index 449282d7..deeaea94 100644 --- a/sope-xml/DOM/README +++ b/sope-xml/DOM/README @@ -29,6 +29,9 @@ Samples: document./uid => DOMElement or array! matching 'uid' document./uid.textValue => text-value of 'uid' element + element.@value.textValue => text-value of 'value' attribute of element + element./subnode.textValue => lookup subnode (strips of the /) using QP + Some info on classes ... ======================== diff --git a/sope-xml/DOM/Version b/sope-xml/DOM/Version index 3c3eedfd..c5124e5b 100644 --- a/sope-xml/DOM/Version +++ b/sope-xml/DOM/Version @@ -1,3 +1,3 @@ # version file -SUBMINOR_VERSION:=17 +SUBMINOR_VERSION:=18 -- 2.39.5