From b7942d301429b7879c1718861ad330df1f211d76 Mon Sep 17 00:00:00 2001 From: helge Date: Sat, 30 Jul 2005 16:12:17 +0000 Subject: [PATCH] improved KVC support in DOM objects git-svn-id: http://svn.opengroupware.org/SOPE/trunk@948 e4a50df8-12e2-0310-a44c-efbce7f8a7e3 --- sope-xml/DOM/ChangeLog | 10 ++++++++++ sope-xml/DOM/DOMDocument.m | 10 ++++++++++ sope-xml/DOM/DOMNode.m | 7 +++++++ sope-xml/DOM/README | 14 ++++++++++++++ sope-xml/DOM/Version | 2 +- 5 files changed, 42 insertions(+), 1 deletion(-) diff --git a/sope-xml/DOM/ChangeLog b/sope-xml/DOM/ChangeLog index ba193a47..d9800e7c 100644 --- a/sope-xml/DOM/ChangeLog +++ b/sope-xml/DOM/ChangeLog @@ -1,3 +1,13 @@ +2005-07-30 Helge Hess + + * v.4.5.17 + + * DOMDocument.m: evaluate KVC keys starting with a slash '/' as query + path expressions + + * DOMNode.m: changed to return 'nil' for unknown KVC keys instead of + raising an exception + 2005-05-03 Helge Hess * DOMTreeWalker.m: fixed a MacOSX 10.4 warning (v4.5.16) diff --git a/sope-xml/DOM/DOMDocument.m b/sope-xml/DOM/DOMDocument.m index cd5da1f8..a47ee2d0 100644 --- a/sope-xml/DOM/DOMDocument.m +++ b/sope-xml/DOM/DOMDocument.m @@ -28,6 +28,7 @@ #include #include #include "DOMSaxBuilder.h" +#include "DOMNode+QueryPath.h" #include "common.h" //#define PROF_DEALLOC 1 @@ -366,4 +367,13 @@ return [self documentElement]; } +/* Key/Value Coding */ + +- (id)valueForKey:(NSString *)_key { + if ([_key hasPrefix:@"/"]) + return [self lookupQueryPath:_key]; + + return [super valueForKey:_key]; +} + @end /* NGDOMDocument */ diff --git a/sope-xml/DOM/DOMNode.m b/sope-xml/DOM/DOMNode.m index 5aa908b6..d7e6c4e0 100644 --- a/sope-xml/DOM/DOMNode.m +++ b/sope-xml/DOM/DOMNode.m @@ -198,6 +198,13 @@ NSString *DOMNodeValue(id _node) { return nil; } +/* key/value coding */ + +- (id)valueForUndefinedKey:(NSString *)_key { + /* default is to raise an exception, we just return nil */ + return nil; +} + /* description */ - (NSString *)description { diff --git a/sope-xml/DOM/README b/sope-xml/DOM/README index dc7a49fb..449282d7 100644 --- a/sope-xml/DOM/README +++ b/sope-xml/DOM/README @@ -16,6 +16,20 @@ How to build a DOM tree ? id document = [builder buildFromSource:@"myfile.xml"]; + +KVC +=== + +You can navigate the DOM tree with standard key/value coding. The NGDOMDocument +will treat all KVC keys starting with a "/" as query path expressions. + +Samples: + document.documentElement => root DOMElement + document.documentElement.childNodes => NSArray containing the root children + document./uid => DOMElement or array! matching 'uid' + document./uid.textValue => text-value of 'uid' element + + Some info on classes ... ======================== diff --git a/sope-xml/DOM/Version b/sope-xml/DOM/Version index 0a8bca08..3c3eedfd 100644 --- a/sope-xml/DOM/Version +++ b/sope-xml/DOM/Version @@ -1,3 +1,3 @@ # version file -SUBMINOR_VERSION:=16 +SUBMINOR_VERSION:=17 -- 2.39.5