added _initWithNode:kind:, changed copyWithZone:, etc.

git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/base/branches/nsxml_using_libxml2@34575 72102866-910b-0410-8b05-ffd578937521
This commit is contained in:
Doug Simons 2012-01-18 15:12:58 +00:00
parent 0c5781882a
commit 78ccfdae11
4 changed files with 71 additions and 26 deletions

View file

@ -75,6 +75,11 @@ GS_PRIVATE_INTERNAL(NSXMLDTD)
return nil;
}
- (void) _createInternal
{
GS_CREATE_INTERNAL(NSXMLDTD);
}
- (id) init
{
return [self initWithKind: NSXMLDTDKind options: 0];

View file

@ -78,6 +78,11 @@ extern void clearPrivatePointers(xmlNodePtr aNode);
return internal->docType;
}
- (void) _createInternal
{
GS_CREATE_INTERNAL(NSXMLDocument);
}
- (id) init
{
return [self initWithKind: NSXMLDocumentKind options: 0];

View file

@ -38,6 +38,7 @@ extern void clearPrivatePointers(xmlNodePtr aNode);
+ (NSXMLNode *) _objectForNode: (xmlNodePtr)node;
- (void) _addSubNode:(NSXMLNode *)subNode;
- (void) _removeSubNode:(NSXMLNode *)subNode;
- (id) _initWithNode:(xmlNodePtr)node kind:(NSXMLNodeKind)kind;
@end
@implementation NSXMLElement
@ -56,6 +57,11 @@ extern void clearPrivatePointers(xmlNodePtr aNode);
[super dealloc];
}
- (void) _createInternal
{
GS_CREATE_INTERNAL(NSXMLElement);
}
- (id) init
{
return [self initWithKind: NSXMLElementKind options: 0];
@ -129,8 +135,12 @@ extern void clearPrivatePointers(xmlNodePtr aNode);
- (void) addAttribute: (NSXMLNode*)attribute
{
xmlNodePtr node = (xmlNodePtr)(internal->node);
xmlNodePtr attr = (xmlNodePtr)[attribute _node];
xmlAddChild(node,attr);
xmlAttrPtr attr = (xmlAttrPtr)[attribute _node];
//xmlAddChild(node,attr);
// xmlSetProp(node, attr->name, attr->children);
xmlAttrPtr newAttr = xmlCopyProp(node, attr);
[attribute _setNode:newAttr];
[self _addSubNode:attribute];
}
- (void) removeAttributeForName: (NSString*)name
@ -397,6 +407,12 @@ extern void clearPrivatePointers(xmlNodePtr aNode);
- (id) copyWithZone: (NSZone *)zone
{
NSXMLElement *c = [[self class] alloc]; ///(NSXMLElement*)[super copyWithZone: zone];
xmlNodePtr newNode = (xmlNodePtr)xmlCopyNode(MY_NODE, 1); // copy recursively
clearPrivatePointers(newNode); // clear out all of the _private pointers in the entire tree
c = [c _initWithNode:newNode kind:internal->kind];
return c;
/*
NSXMLElement *c = (NSXMLElement*)[super copyWithZone: zone];
NSEnumerator *en;
id obj;
@ -429,6 +445,7 @@ extern void clearPrivatePointers(xmlNodePtr aNode);
}
return c;
*/
}
@end

View file

@ -36,6 +36,7 @@ GS_PRIVATE_INTERNAL(NSXMLNode)
+ (NSXMLNode *) _objectForNode: (xmlNodePtr)node;
- (void) _addSubNode:(NSXMLNode *)subNode;
- (void) _removeSubNode:(NSXMLNode *)subNode;
- (id) _initWithNode:(xmlNodePtr)node kind:(NSXMLNodeKind)kind;
@end
@implementation NSXMLNode (Private)
@ -63,42 +64,38 @@ GS_PRIVATE_INTERNAL(NSXMLNode)
if(result == nil)
{
NSXMLNode *parent = nil;
switch(type)
{
case(XML_DOCUMENT_NODE):
result = [[NSXMLDocument alloc] initWithKind: NSXMLDocumentKind];
result = [[NSXMLDocument alloc] _initWithNode:node kind: NSXMLDocumentKind];
break;
case(XML_ELEMENT_NODE):
result = [[NSXMLElement alloc] initWithKind: NSXMLElementKind];
result = [[NSXMLElement alloc] _initWithNode:node kind: NSXMLElementKind];
break;
case(XML_TEXT_NODE):
result = [[self alloc] initWithKind: NSXMLTextKind];
result = [[self alloc] _initWithNode:node kind: NSXMLTextKind];
break;
case(XML_PI_NODE):
result = [[self alloc] initWithKind: NSXMLProcessingInstructionKind];
result = [[self alloc] _initWithNode:node kind: NSXMLProcessingInstructionKind];
break;
case(XML_COMMENT_NODE):
result = [[self alloc] initWithKind: NSXMLCommentKind];
result = [[self alloc] _initWithNode:node kind: NSXMLCommentKind];
break;
case(XML_ATTRIBUTE_NODE):
result = [[self alloc] initWithKind: NSXMLAttributeKind];
result = [[self alloc] _initWithNode:node kind: NSXMLAttributeKind];
[result setStringValue: StringFromXMLStringPtr(node->content)];
break;
default:
NSLog(@"ERROR: _objectForNode: called with a node of type %d", type);
break;
}
if(node && [result _node] != NULL)
{
xmlFree([result _node]);
}
[result _setNode:node];
//[result _setNode:node];
AUTORELEASE(result);
if (node->parent)
parent = [NSXMLNode _objectForNode:node->parent];
[parent _addSubNode:result];
{
NSXMLNode *parent = [NSXMLNode _objectForNode:node->parent];
[parent _addSubNode:result];
}
}
}
@ -144,6 +141,22 @@ GS_PRIVATE_INTERNAL(NSXMLNode)
[internal->subNodes removeObjectIdenticalTo:subNode];
}
- (void) _createInternal
{
GS_CREATE_INTERNAL(NSXMLNode);
}
- (id) _initWithNode:(xmlNodePtr)node kind:(NSXMLNodeKind)kind
{
if ((self = [super init]))
{
[self _createInternal];
[self _setNode:node];
internal->kind = kind;
}
return self;
}
@end
void clearPrivatePointers(xmlNodePtr aNode)
@ -253,7 +266,16 @@ NSArray *execute_xpath(NSXMLNode *node,
/* results */
nodeset = xpathObj->nodesetval;
/*
if (nodeset == NULL || nodeset->nodeNr == 0)
{
xpathObj = xmlXPathEval(xpathExpr, xpathCtx);
if (xpathObj != NULL)
nodeset = xpathObj->nodesetval;
if (nodeset)
NSLog(@"Succeeded in evaluating as a path, using xmlXPathEval");
}
*/
if(nodeset)
{
/* Collect results */
@ -505,8 +527,9 @@ NSArray *execute_xpath(NSXMLNode *node,
xmlNodePtr newNode = xmlCopyNode([self _node], 1); // make a deep copy
clearPrivatePointers(newNode);
c = [c initWithKind: internal->kind options: internal->options];
[c _setNode:newNode];
//c = [c initWithKind: internal->kind options: internal->options];
//[c _setNode:newNode];
c = [c _initWithNode:newNode kind:internal->kind];
@ -950,11 +973,6 @@ NSArray *execute_xpath(NSXMLNode *node,
- (NSArray*) nodesForXPath: (NSString*)anxpath error: (NSError**)error
{
if([[anxpath substringWithRange: NSMakeRange(0,1)] isEqual: @"/"] == NO)
{
anxpath = [@"/" stringByAppendingString: anxpath];
}
*error = NULL;
return execute_xpath(self, anxpath, NULL);
}