mirror of
https://github.com/gnustep/libs-base.git
synced 2025-05-30 16:30:41 +00:00
* 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:
parent
aa8a33f26c
commit
6cbe121535
7 changed files with 73 additions and 62 deletions
10
ChangeLog
10
ChangeLog
|
@ -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>
|
2012-01-03 14:22-EST Gregory John Casamento <greg.casamento@gmail.com>
|
||||||
|
|
||||||
* Source/NSXMLDocument.m: Implement XMLStringWithOptions:
|
* Source/NSXMLDocument.m: Implement XMLStringWithOptions:
|
||||||
|
|
|
@ -79,8 +79,6 @@ typedef NSUInteger NSXMLDocumentContentKind;
|
||||||
NSString *_encoding;
|
NSString *_encoding;
|
||||||
NSString *_version;
|
NSString *_version;
|
||||||
NSXMLDTD *_docType;
|
NSXMLDTD *_docType;
|
||||||
NSArray *_children;
|
|
||||||
BOOL _childrenHaveMutated;
|
|
||||||
BOOL _standalone;
|
BOOL _standalone;
|
||||||
NSXMLElement *_rootElement;
|
NSXMLElement *_rootElement;
|
||||||
NSString *_URI;
|
NSString *_URI;
|
||||||
|
|
|
@ -43,8 +43,6 @@ extern "C" {
|
||||||
@protected
|
@protected
|
||||||
NSMutableDictionary *_attributes;
|
NSMutableDictionary *_attributes;
|
||||||
NSMutableArray *_namespaces;
|
NSMutableArray *_namespaces;
|
||||||
NSMutableArray *_children;
|
|
||||||
BOOL _childrenHaveMutated;
|
|
||||||
NSInteger _prefixIndex;
|
NSInteger _prefixIndex;
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
|
@ -80,29 +80,20 @@ typedef NSUInteger NSXMLNodeKind;
|
||||||
*/
|
*/
|
||||||
@interface NSXMLNode : NSObject <NSCopying>
|
@interface NSXMLNode : NSObject <NSCopying>
|
||||||
{
|
{
|
||||||
#if GS_EXPOSE(NSXMLNode)
|
|
||||||
@protected
|
@protected
|
||||||
void *_handle;
|
void *_handle;
|
||||||
NSXMLNodeKind _kind;
|
NSXMLNodeKind _kind;
|
||||||
NSXMLNode *_parent;
|
NSXMLNode *_parent;
|
||||||
NSUInteger _index;
|
NSUInteger _index;
|
||||||
id _objectValue;
|
id _objectValue;
|
||||||
NSString *_stringValue;
|
NSString *_stringValue;
|
||||||
NSString *_name;
|
NSString *_name;
|
||||||
NSString *_URI;
|
NSString *_URI;
|
||||||
#endif
|
NSMutableArray *_children;
|
||||||
#if GS_NONFRAGILE
|
NSUInteger _childCount;
|
||||||
# if defined(GS_NSXMLNode_IVARS)
|
NSXMLNode *_previousSibling;
|
||||||
@public GS_NSXMLNode_IVARS
|
NSXMLNode *_nextSibling;
|
||||||
# endif
|
NSUInteger _options;
|
||||||
#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
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -43,7 +43,6 @@
|
||||||
RELEASE(_encoding);
|
RELEASE(_encoding);
|
||||||
RELEASE(_version);
|
RELEASE(_version);
|
||||||
RELEASE(_docType);
|
RELEASE(_docType);
|
||||||
RELEASE(_children);
|
|
||||||
RELEASE(_URI);
|
RELEASE(_URI);
|
||||||
RELEASE(_MIMEType);
|
RELEASE(_MIMEType);
|
||||||
RELEASE(_elementStack);
|
RELEASE(_elementStack);
|
||||||
|
@ -90,13 +89,16 @@
|
||||||
if (parser != nil)
|
if (parser != nil)
|
||||||
{
|
{
|
||||||
_standalone = YES;
|
_standalone = YES;
|
||||||
_children = [[NSMutableArray alloc] initWithCapacity: 10];
|
|
||||||
_elementStack = [[NSMutableArray alloc] initWithCapacity: 10];
|
_elementStack = [[NSMutableArray alloc] initWithCapacity: 10];
|
||||||
ASSIGN(_xmlData, data);
|
ASSIGN(_xmlData, data);
|
||||||
[parser setDelegate: self];
|
[parser setDelegate: self];
|
||||||
[parser parse];
|
[parser parse];
|
||||||
RELEASE(parser);
|
RELEASE(parser);
|
||||||
}
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
return nil;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return self;
|
return self;
|
||||||
}
|
}
|
||||||
|
@ -110,9 +112,13 @@
|
||||||
element,
|
element,
|
||||||
self];
|
self];
|
||||||
}
|
}
|
||||||
self = [self initWithData: nil options: 0 error: 0];
|
self = [self init];
|
||||||
if (self != nil)
|
if (self != nil)
|
||||||
{
|
{
|
||||||
|
_standalone = YES;
|
||||||
|
_children = [[NSMutableArray alloc] initWithCapacity: 10];
|
||||||
|
_elementStack = [[NSMutableArray alloc] initWithCapacity: 10];
|
||||||
|
|
||||||
[self setRootElement: (NSXMLNode*)element];
|
[self setRootElement: (NSXMLNode*)element];
|
||||||
}
|
}
|
||||||
return self;
|
return self;
|
||||||
|
@ -199,7 +205,7 @@
|
||||||
{
|
{
|
||||||
[child setParent: self];
|
[child setParent: self];
|
||||||
[(NSMutableArray *)_children insertObject: child atIndex: index];
|
[(NSMutableArray *)_children insertObject: child atIndex: index];
|
||||||
_childrenHaveMutated = YES;
|
// _childrenHaveMutated = YES;
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void) insertChildren: (NSArray*)children atIndex: (NSUInteger)index
|
- (void) insertChildren: (NSArray*)children atIndex: (NSUInteger)index
|
||||||
|
@ -215,8 +221,8 @@
|
||||||
|
|
||||||
- (void) removeChildAtIndex: (NSUInteger)index
|
- (void) removeChildAtIndex: (NSUInteger)index
|
||||||
{
|
{
|
||||||
[(NSMutableArray *)_children removeObjectAtIndex: index];
|
[_children removeObjectAtIndex: index];
|
||||||
_childrenHaveMutated = YES;
|
// _childrenHaveMutated = YES;
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void) setChildren: (NSArray*)children
|
- (void) setChildren: (NSArray*)children
|
||||||
|
@ -288,7 +294,13 @@
|
||||||
NSEnumerator *en = [_children objectEnumerator];
|
NSEnumerator *en = [_children objectEnumerator];
|
||||||
id obj = nil;
|
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)
|
while((obj = [en nextObject]) != nil)
|
||||||
{
|
{
|
||||||
[string appendString: [obj XMLStringWithOptions: options]];
|
[string appendString: [obj XMLStringWithOptions: options]];
|
||||||
|
@ -306,9 +318,11 @@
|
||||||
qualifiedName: (NSString *)qualifiedName
|
qualifiedName: (NSString *)qualifiedName
|
||||||
attributes: (NSDictionary *)attributeDict
|
attributes: (NSDictionary *)attributeDict
|
||||||
{
|
{
|
||||||
|
NSXMLElement *lastElement = [_elementStack lastObject];
|
||||||
NSXMLElement *currentElement =
|
NSXMLElement *currentElement =
|
||||||
[[NSXMLElement alloc] initWithName: elementName];
|
[[NSXMLElement alloc] initWithName: elementName];
|
||||||
|
|
||||||
|
[lastElement addChild: currentElement];
|
||||||
[_elementStack addObject: currentElement];
|
[_elementStack addObject: currentElement];
|
||||||
if (_rootElement == nil)
|
if (_rootElement == nil)
|
||||||
{
|
{
|
||||||
|
|
|
@ -32,7 +32,6 @@
|
||||||
{
|
{
|
||||||
[_attributes release];
|
[_attributes release];
|
||||||
[_namespaces release];
|
[_namespaces release];
|
||||||
[_children release];
|
|
||||||
[super dealloc];
|
[super dealloc];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -105,7 +104,15 @@
|
||||||
|
|
||||||
- (void) setAttributesAsDictionary: (NSDictionary*)attributes
|
- (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
|
- (NSArray*) attributes
|
||||||
|
@ -191,13 +198,14 @@
|
||||||
- (void) setChildren: (NSArray*)children
|
- (void) setChildren: (NSArray*)children
|
||||||
{
|
{
|
||||||
ASSIGN(_children, [children mutableCopy]);
|
ASSIGN(_children, [children mutableCopy]);
|
||||||
_childrenHaveMutated = YES;
|
// _childrenHaveMutated = YES;
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void) addChild: (NSXMLNode*)child
|
- (void) addChild: (NSXMLNode*)child
|
||||||
{
|
{
|
||||||
|
[child setParent: self];
|
||||||
[_children addObject: child];
|
[_children addObject: child];
|
||||||
_childrenHaveMutated = YES;
|
// _childrenHaveMutated = YES;
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void) replaceChildAtIndex: (NSUInteger)index withNode: (NSXMLNode*)node
|
- (void) replaceChildAtIndex: (NSUInteger)index withNode: (NSXMLNode*)node
|
||||||
|
|
|
@ -36,17 +36,7 @@
|
||||||
* performance quite a bit. So we cache the siblings and update them when the
|
* performance quite a bit. So we cache the siblings and update them when the
|
||||||
* nodes are changed.
|
* 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"
|
#import "NSXMLPrivate.h"
|
||||||
|
|
||||||
|
@ -211,17 +201,17 @@ GS_PRIVATE_INTERNAL(NSXMLNode)
|
||||||
|
|
||||||
- (NSXMLNode*) childAtIndex: (NSUInteger)index
|
- (NSXMLNode*) childAtIndex: (NSUInteger)index
|
||||||
{
|
{
|
||||||
return [internal->children objectAtIndex: index];
|
return [_children objectAtIndex: index];
|
||||||
}
|
}
|
||||||
|
|
||||||
- (NSUInteger) childCount
|
- (NSUInteger) childCount
|
||||||
{
|
{
|
||||||
return internal->childCount;
|
return _childCount;
|
||||||
}
|
}
|
||||||
|
|
||||||
- (NSArray*)children
|
- (NSArray*)children
|
||||||
{
|
{
|
||||||
return internal->children;
|
return _children;
|
||||||
}
|
}
|
||||||
|
|
||||||
- (id) copyWithZone: (NSZone*)zone
|
- (id) copyWithZone: (NSZone*)zone
|
||||||
|
@ -232,8 +222,8 @@ GS_PRIVATE_INTERNAL(NSXMLNode)
|
||||||
- (void) dealloc
|
- (void) dealloc
|
||||||
{
|
{
|
||||||
[self detach];
|
[self detach];
|
||||||
[internal->children release];
|
[_children release];
|
||||||
GS_DESTROY_INTERNAL(NSXMLNode);
|
[_URI release];
|
||||||
[_objectValue release];
|
[_objectValue release];
|
||||||
[_stringValue release];
|
[_stringValue release];
|
||||||
[super dealloc];
|
[super dealloc];
|
||||||
|
@ -272,7 +262,9 @@ GS_PRIVATE_INTERNAL(NSXMLNode)
|
||||||
return nil;
|
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:
|
* We find the correct subclass for specific node kinds:
|
||||||
|
@ -325,8 +317,8 @@ GS_PRIVATE_INTERNAL(NSXMLNode)
|
||||||
*/
|
*/
|
||||||
|
|
||||||
_kind = kind;
|
_kind = kind;
|
||||||
internal->options = theOptions;
|
_options = theOptions;
|
||||||
internal->children = [NSMutableArray new];
|
_children = [NSMutableArray new];
|
||||||
return self;
|
return self;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -364,14 +356,14 @@ GS_PRIVATE_INTERNAL(NSXMLNode)
|
||||||
NSXMLNode *candidate = nil;
|
NSXMLNode *candidate = nil;
|
||||||
|
|
||||||
/* Node walking is a depth-first thingy. Hence, we consider children first: */
|
/* Node walking is a depth-first thingy. Hence, we consider children first: */
|
||||||
if (0 != internal->childCount)
|
if (0 != _childCount)
|
||||||
{
|
{
|
||||||
NSUInteger theIndex = 0;
|
NSUInteger theIndex = 0;
|
||||||
if (NO == forward)
|
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: */
|
/* If there are no children, we move on to siblings: */
|
||||||
|
@ -379,11 +371,11 @@ GS_PRIVATE_INTERNAL(NSXMLNode)
|
||||||
{
|
{
|
||||||
if (forward)
|
if (forward)
|
||||||
{
|
{
|
||||||
candidate = internal->nextSibling;
|
candidate = _nextSibling;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
candidate = internal->previousSibling;
|
candidate = _previousSibling;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -425,7 +417,7 @@ GS_PRIVATE_INTERNAL(NSXMLNode)
|
||||||
|
|
||||||
- (NSXMLNode*) nextSibling
|
- (NSXMLNode*) nextSibling
|
||||||
{
|
{
|
||||||
return internal->nextSibling;
|
return _nextSibling;
|
||||||
}
|
}
|
||||||
|
|
||||||
- (id) objectValue
|
- (id) objectValue
|
||||||
|
@ -450,7 +442,7 @@ GS_PRIVATE_INTERNAL(NSXMLNode)
|
||||||
|
|
||||||
- (NSXMLNode*) previousSibling
|
- (NSXMLNode*) previousSibling
|
||||||
{
|
{
|
||||||
return internal->previousSibling;
|
return _previousSibling;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue