Permalink
Browse files

Merge remote-tracking branch 'refs/remotes/DaGaMs/feature/ARC'

Conflicts:
	Source/CXMLElement_CreationExtensions.m
	Source/CXMLNode.h
  • Loading branch information...
2 parents 1318d0d + fcfe14b commit 74af574dff41de98d7f149fd30b331df9c129fd6 Jan Weiß committed Jan 28, 2014
@@ -36,4 +36,6 @@
- (void)addChild:(CXMLNode *)inNode;
- (void)addNamespace:(CXMLNode *)inNamespace;
+- (void)removeAttributeForName:(NSString *)name;
+- (id)initWithXMLString:(NSString *)string error:(NSError **)error;
@end
@@ -30,9 +30,26 @@
// or implied, of toxicsoftware.com.
#import "CXMLElement_CreationExtensions.h"
+#import "CXMLNode_CreationExtensions.h"
+#import "CXMLDocument.h"
@implementation CXMLElement (CXMLElement_CreationExtensions)
+- (id)initWithXMLString:(NSString *)string error:(NSError **)error
+{
+ CXMLDocument *doc = [[CXMLDocument alloc] initWithXMLString:string options:nil error:error];
+ if (!doc)
+ {
+ return nil;
+ }
+
+ if ((self = [doc rootElement]))
+ {
+ [self detach];
+ }
+ return self;
+}
+
- (void)addChild:(CXMLNode *)inNode
{
NSAssert(inNode->_node->doc == NULL, @"Cannot addChild with a node that already is part of a document. Copy it first!");
@@ -56,4 +73,26 @@ - (void)setStringValue:(NSString *)inStringValue
xmlAddChild(self->_node, theContentNode);
}
+- (void)removeAttributeForName:(NSString *)name
+{
+ CXMLNode *node = [self attributeForName:name];
+ xmlUnlinkNode(node->_node);
+ xmlFree(node->_node);
+}
+
+- (void)setChildren:(NSArray *)children
+{
+ for (CXMLNode *child in [[self children] copy])
+ {
+ BOOL alreadyContained = [self.children containsObject:child];
+ xmlUnlinkNode(child->_node);
+ if (!alreadyContained) xmlFree(child->_node);
+ }
+
+ for (CXMLNode *child in children)
+ {
+ [self addChild:child];
+ }
+}
+
@end
View
@@ -34,26 +34,26 @@
#include <libxml/tree.h>
typedef enum {
- CXMLInvalidKind = 0,
- CXMLElementKind = XML_ELEMENT_NODE,
- CXMLAttributeKind = XML_ATTRIBUTE_NODE,
- CXMLTextKind = XML_TEXT_NODE,
- CXMLProcessingInstructionKind = XML_PI_NODE,
- CXMLCommentKind = XML_COMMENT_NODE,
- CXMLNotationDeclarationKind = XML_NOTATION_NODE,
- CXMLDTDKind = XML_DTD_NODE,
- CXMLElementDeclarationKind = XML_ELEMENT_DECL,
- CXMLAttributeDeclarationKind = XML_ATTRIBUTE_DECL,
- CXMLEntityDeclarationKind = XML_ENTITY_DECL,
- CXMLNamespaceKind = XML_NAMESPACE_DECL,
+ CXMLInvalidKind = 0,
+ CXMLElementKind = XML_ELEMENT_NODE,
+ CXMLAttributeKind = XML_ATTRIBUTE_NODE,
+ CXMLTextKind = XML_TEXT_NODE,
+ CXMLProcessingInstructionKind = XML_PI_NODE,
+ CXMLCommentKind = XML_COMMENT_NODE,
+ CXMLNotationDeclarationKind = XML_NOTATION_NODE,
+ CXMLDTDKind = XML_DTD_NODE,
+ CXMLElementDeclarationKind = XML_ELEMENT_DECL,
+ CXMLAttributeDeclarationKind = XML_ATTRIBUTE_DECL,
+ CXMLEntityDeclarationKind = XML_ENTITY_DECL,
+ CXMLNamespaceKind = XML_NAMESPACE_DECL,
} CXMLNodeKind;
@class CXMLDocument;
// NSXMLNode
@interface CXMLNode : NSObject <NSCopying> {
- xmlNodePtr _node;
- BOOL _freeNodeOnRelease;
+ xmlNodePtr _node;
+ BOOL _freeNodeOnRelease;
}
- (CXMLNodeKind)kind;
@@ -68,6 +68,9 @@ typedef enum {
- (CXMLNode *)childAtIndex:(NSUInteger)index;
- (CXMLNode *)previousSibling;
- (CXMLNode *)nextSibling;
+- (CXMLNode *)previousNode;
+- (CXMLNode *)nextNode;
+//- (NSString *)XPath;
- (NSString *)localName;
- (NSString *)prefix;
- (NSString *)URI;
@@ -77,6 +80,6 @@ typedef enum {
- (NSString *)description;
- (NSString *)XMLString;
- (NSString *)XMLStringWithOptions:(NSUInteger)options;
+//- (NSString *)canonicalXMLStringPreservingComments:(BOOL)comments;
- (NSArray *)nodesForXPath:(NSString *)xpath error:(NSError **)error;
-
@end
View
@@ -223,8 +223,16 @@ - (CXMLNode *)nextSibling
return([CXMLNode nodeWithLibXMLNode:_node->next freeOnDealloc:NO]);
}
-//- (CXMLNode *)previousNode;
-//- (CXMLNode *)nextNode;
+- (CXMLNode *)nextNode
+{
+ return [self nextSibling];
+}
+
+- (CXMLNode *)previousNode
+{
+ return [self previousSibling];
+}
+
//- (NSString *)XPath;
- (NSString *)localName
@@ -43,5 +43,5 @@
+ (id)namespaceWithName:(NSString *)name stringValue:(NSString *)stringValue;
+ (id)processingInstructionWithName:(NSString *)name stringValue:(NSString *)stringValue;
- (void)setStringValue:(NSString *)inStringValue;
-
+- (void)detach;
@end
@@ -101,5 +101,11 @@ - (void)setStringValue:(NSString *)inStringValue
xmlNodeSetContent(_node, (const xmlChar *)[inStringValue UTF8String]);
}
+- (void)detach
+{
+ xmlUnlinkNode(self->_node);
+ xmlFree(_node);
+}
+
@end

0 comments on commit 74af574

Please sign in to comment.