* 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 <greg.casamento@gmail.com>



git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/base/trunk@34408 72102866-910b-0410-8b05-ffd578937521
This commit is contained in:
gcasa 2012-01-03 21:42:33 +00:00
parent 0b7ae8929b
commit 9a24dd2985
7 changed files with 73 additions and 62 deletions

View file

@ -1,3 +1,13 @@
2012-01-03 16:33-EST Gregory John Casamento <greg.casamento@gmail.com>
* 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 <greg.casamento@gmail.com>
* Source/NSXMLDocument.m: Implement XMLStringWithOptions:

View file

@ -79,8 +79,6 @@ typedef NSUInteger NSXMLDocumentContentKind;
NSString *_encoding;
NSString *_version;
NSXMLDTD *_docType;
NSArray *_children;
BOOL _childrenHaveMutated;
BOOL _standalone;
NSXMLElement *_rootElement;
NSString *_URI;

View file

@ -43,8 +43,6 @@ extern "C" {
@protected
NSMutableDictionary *_attributes;
NSMutableArray *_namespaces;
NSMutableArray *_children;
BOOL _childrenHaveMutated;
NSInteger _prefixIndex;
#endif
}

View file

@ -80,29 +80,20 @@ typedef NSUInteger NSXMLNodeKind;
*/
@interface NSXMLNode : NSObject <NSCopying>
{
#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;
}
/**

View file

@ -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: @"<?xml version=\"1.0\"?>"];
[string appendString: @"<?xml version=\"1.0\""];
if(_standalone == YES)
{
[string appendString: @" standalone=\"yes\""];
}
[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)
{

View file

@ -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

View file

@ -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;
}