From 6cbe1215356327b23f3254723d7e7f2cc1db29e4 Mon Sep 17 00:00:00 2001 From: Gregory John Casamento Date: Tue, 3 Jan 2012 21:42:33 +0000 Subject: [PATCH] * Headers/Foundation/NSXMLDocument.h * Headers/Foundation/NSXMLElement.h * Headers/Foundation/NSXMLNode.h: Move declarations. * Source/NSXMLDocument.m: Correct parsing issues. * Source/NSXMLElement.m: Remove local declaration of _children * Source/NSXMLNode.m: Remove internal. Move all declarations here directly. 2012-01-03 14:22-EST Gregory John Casamento git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/base/trunk@34408 72102866-910b-0410-8b05-ffd578937521 --- ChangeLog | 10 +++++++ Headers/Foundation/NSXMLDocument.h | 2 -- Headers/Foundation/NSXMLElement.h | 2 -- Headers/Foundation/NSXMLNode.h | 35 +++++++++---------------- Source/NSXMLDocument.m | 28 +++++++++++++++----- Source/NSXMLElement.m | 16 +++++++++--- Source/NSXMLNode.m | 42 ++++++++++++------------------ 7 files changed, 73 insertions(+), 62 deletions(-) diff --git a/ChangeLog b/ChangeLog index 944d87c4c..829ebca32 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,13 @@ +2012-01-03 16:33-EST Gregory John Casamento + + * Headers/Foundation/NSXMLDocument.h + * Headers/Foundation/NSXMLElement.h + * Headers/Foundation/NSXMLNode.h: Move declarations. + * Source/NSXMLDocument.m: Correct parsing issues. + * Source/NSXMLElement.m: Remove local declaration of _children + * Source/NSXMLNode.m: Remove internal. Move all declarations here + directly. + 2012-01-03 14:22-EST Gregory John Casamento * Source/NSXMLDocument.m: Implement XMLStringWithOptions: diff --git a/Headers/Foundation/NSXMLDocument.h b/Headers/Foundation/NSXMLDocument.h index e09651284..2df0c9a48 100644 --- a/Headers/Foundation/NSXMLDocument.h +++ b/Headers/Foundation/NSXMLDocument.h @@ -79,8 +79,6 @@ typedef NSUInteger NSXMLDocumentContentKind; NSString *_encoding; NSString *_version; NSXMLDTD *_docType; - NSArray *_children; - BOOL _childrenHaveMutated; BOOL _standalone; NSXMLElement *_rootElement; NSString *_URI; diff --git a/Headers/Foundation/NSXMLElement.h b/Headers/Foundation/NSXMLElement.h index c66d06888..764143009 100644 --- a/Headers/Foundation/NSXMLElement.h +++ b/Headers/Foundation/NSXMLElement.h @@ -43,8 +43,6 @@ extern "C" { @protected NSMutableDictionary *_attributes; NSMutableArray *_namespaces; - NSMutableArray *_children; - BOOL _childrenHaveMutated; NSInteger _prefixIndex; #endif } diff --git a/Headers/Foundation/NSXMLNode.h b/Headers/Foundation/NSXMLNode.h index 1eb2c8c92..e0f8d16e5 100644 --- a/Headers/Foundation/NSXMLNode.h +++ b/Headers/Foundation/NSXMLNode.h @@ -80,29 +80,20 @@ typedef NSUInteger NSXMLNodeKind; */ @interface NSXMLNode : NSObject { -#if GS_EXPOSE(NSXMLNode) @protected - void *_handle; - NSXMLNodeKind _kind; - NSXMLNode *_parent; - NSUInteger _index; - id _objectValue; - NSString *_stringValue; - NSString *_name; - NSString *_URI; -#endif -#if GS_NONFRAGILE -# if defined(GS_NSXMLNode_IVARS) -@public GS_NSXMLNode_IVARS -# endif -#else - /* Pointer to private additional data used to avoid breaking ABI - * when we don't have the non-fragile ABI available. - * Use this mechanism rather than changing the instance variable - * layout (see Source/GSInternal.h for details). - */ - @private id _internal GS_UNUSED_IVAR; -#endif + void *_handle; + NSXMLNodeKind _kind; + NSXMLNode *_parent; + NSUInteger _index; + id _objectValue; + NSString *_stringValue; + NSString *_name; + NSString *_URI; + NSMutableArray *_children; + NSUInteger _childCount; + NSXMLNode *_previousSibling; + NSXMLNode *_nextSibling; + NSUInteger _options; } /** diff --git a/Source/NSXMLDocument.m b/Source/NSXMLDocument.m index 2924ca0a9..34c6e1630 100644 --- a/Source/NSXMLDocument.m +++ b/Source/NSXMLDocument.m @@ -43,7 +43,6 @@ RELEASE(_encoding); RELEASE(_version); RELEASE(_docType); - RELEASE(_children); RELEASE(_URI); RELEASE(_MIMEType); RELEASE(_elementStack); @@ -90,13 +89,16 @@ if (parser != nil) { _standalone = YES; - _children = [[NSMutableArray alloc] initWithCapacity: 10]; _elementStack = [[NSMutableArray alloc] initWithCapacity: 10]; ASSIGN(_xmlData, data); [parser setDelegate: self]; [parser parse]; RELEASE(parser); } + else + { + return nil; + } } return self; } @@ -110,9 +112,13 @@ element, self]; } - self = [self initWithData: nil options: 0 error: 0]; + self = [self init]; if (self != nil) { + _standalone = YES; + _children = [[NSMutableArray alloc] initWithCapacity: 10]; + _elementStack = [[NSMutableArray alloc] initWithCapacity: 10]; + [self setRootElement: (NSXMLNode*)element]; } return self; @@ -199,7 +205,7 @@ { [child setParent: self]; [(NSMutableArray *)_children insertObject: child atIndex: index]; - _childrenHaveMutated = YES; + // _childrenHaveMutated = YES; } - (void) insertChildren: (NSArray*)children atIndex: (NSUInteger)index @@ -215,8 +221,8 @@ - (void) removeChildAtIndex: (NSUInteger)index { - [(NSMutableArray *)_children removeObjectAtIndex: index]; - _childrenHaveMutated = YES; + [_children removeObjectAtIndex: index]; + // _childrenHaveMutated = YES; } - (void) setChildren: (NSArray*)children @@ -288,7 +294,13 @@ NSEnumerator *en = [_children objectEnumerator]; id obj = nil; - [string appendString: @""]; + [string appendString: @"\n"]; + while((obj = [en nextObject]) != nil) { [string appendString: [obj XMLStringWithOptions: options]]; @@ -306,9 +318,11 @@ qualifiedName: (NSString *)qualifiedName attributes: (NSDictionary *)attributeDict { + NSXMLElement *lastElement = [_elementStack lastObject]; NSXMLElement *currentElement = [[NSXMLElement alloc] initWithName: elementName]; + [lastElement addChild: currentElement]; [_elementStack addObject: currentElement]; if (_rootElement == nil) { diff --git a/Source/NSXMLElement.m b/Source/NSXMLElement.m index 928961cd9..5911c162f 100644 --- a/Source/NSXMLElement.m +++ b/Source/NSXMLElement.m @@ -32,7 +32,6 @@ { [_attributes release]; [_namespaces release]; - [_children release]; [super dealloc]; } @@ -105,7 +104,15 @@ - (void) setAttributesAsDictionary: (NSDictionary*)attributes { - ASSIGN(_attributes, [attributes mutableCopy]); + NSString *key = nil; + NSEnumerator *en = [attributes keyEnumerator]; + + while((key = [en nextObject]) != nil) + { + NSXMLNode *attribute = [NSXMLNode attributeWithName: key + stringValue: [attributes objectForKey: key]]; + [self addAttribute: attribute]; + } } - (NSArray*) attributes @@ -191,13 +198,14 @@ - (void) setChildren: (NSArray*)children { ASSIGN(_children, [children mutableCopy]); - _childrenHaveMutated = YES; + // _childrenHaveMutated = YES; } - (void) addChild: (NSXMLNode*)child { + [child setParent: self]; [_children addObject: child]; - _childrenHaveMutated = YES; + // _childrenHaveMutated = YES; } - (void) replaceChildAtIndex: (NSUInteger)index withNode: (NSXMLNode*)node diff --git a/Source/NSXMLNode.m b/Source/NSXMLNode.m index f4b2b8482..e2378cb08 100644 --- a/Source/NSXMLNode.m +++ b/Source/NSXMLNode.m @@ -36,17 +36,7 @@ * performance quite a bit. So we cache the siblings and update them when the * nodes are changed. */ -#define GS_NSXMLNode_IVARS \ - NSMutableArray *children; \ - NSUInteger childCount; \ - NSXMLNode *previousSibling; \ - NSXMLNode *nextSibling; \ - NSUInteger options; -#define GSInternal NSXMLNodeInternal -#include "GSInternal.h" -@class NSXMLNode; -GS_PRIVATE_INTERNAL(NSXMLNode) #import "NSXMLPrivate.h" @@ -211,17 +201,17 @@ GS_PRIVATE_INTERNAL(NSXMLNode) - (NSXMLNode*) childAtIndex: (NSUInteger)index { - return [internal->children objectAtIndex: index]; + return [_children objectAtIndex: index]; } - (NSUInteger) childCount { - return internal->childCount; + return _childCount; } - (NSArray*)children { - return internal->children; + return _children; } - (id) copyWithZone: (NSZone*)zone @@ -232,8 +222,8 @@ GS_PRIVATE_INTERNAL(NSXMLNode) - (void) dealloc { [self detach]; - [internal->children release]; - GS_DESTROY_INTERNAL(NSXMLNode); + [_children release]; + [_URI release]; [_objectValue release]; [_stringValue release]; [super dealloc]; @@ -272,7 +262,9 @@ GS_PRIVATE_INTERNAL(NSXMLNode) return nil; } - GS_CREATE_INTERNAL(NSXMLNode) + // GS_CREATE_INTERNAL(NSXMLNode) + _children = [[NSMutableArray alloc] initWithCapacity: 10]; + _childCount = 0; /* * We find the correct subclass for specific node kinds: @@ -325,8 +317,8 @@ GS_PRIVATE_INTERNAL(NSXMLNode) */ _kind = kind; - internal->options = theOptions; - internal->children = [NSMutableArray new]; + _options = theOptions; + _children = [NSMutableArray new]; return self; } @@ -364,14 +356,14 @@ GS_PRIVATE_INTERNAL(NSXMLNode) NSXMLNode *candidate = nil; /* Node walking is a depth-first thingy. Hence, we consider children first: */ - if (0 != internal->childCount) + if (0 != _childCount) { NSUInteger theIndex = 0; if (NO == forward) { - theIndex = (internal->childCount) - 1; + theIndex = (_childCount) - 1; } - candidate = [internal->children objectAtIndex: theIndex]; + candidate = [_children objectAtIndex: theIndex]; } /* If there are no children, we move on to siblings: */ @@ -379,11 +371,11 @@ GS_PRIVATE_INTERNAL(NSXMLNode) { if (forward) { - candidate = internal->nextSibling; + candidate = _nextSibling; } else { - candidate = internal->previousSibling; + candidate = _previousSibling; } } @@ -425,7 +417,7 @@ GS_PRIVATE_INTERNAL(NSXMLNode) - (NSXMLNode*) nextSibling { - return internal->nextSibling; + return _nextSibling; } - (id) objectValue @@ -450,7 +442,7 @@ GS_PRIVATE_INTERNAL(NSXMLNode) - (NSXMLNode*) previousSibling { - return internal->previousSibling; + return _previousSibling; }