Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Adding implementation of DDXMLElement's initWithXMLString:error:

  • Loading branch information...
commit b54de0e16dd40a353767df82598972838605c77d 1 parent 4f970fc
@robbiehanson authored
Showing with 42 additions and 1 deletion.
  1. +1 −1  DDXMLElement.h
  2. +16 −0 DDXMLElement.m
  3. +25 −0 DDXMLTesting.m
View
2  DDXMLElement.h
@@ -9,7 +9,7 @@
- (id)initWithName:(NSString *)name;
- (id)initWithName:(NSString *)name URI:(NSString *)URI;
- (id)initWithName:(NSString *)name stringValue:(NSString *)string;
-//- (id)initWithXMLString:(NSString *)string error:(NSError **)error;
+- (id)initWithXMLString:(NSString *)string error:(NSError **)error;
#pragma mark --- Elements by name ---
View
16 DDXMLElement.m
@@ -38,6 +38,22 @@ - (id)initWithName:(NSString *)name stringValue:(NSString *)string
return result;
}
+- (id)initWithXMLString:(NSString *)string error:(NSError **)error
+{
+ DDXMLDocument *doc = [[DDXMLDocument alloc] initWithXMLString:string options:0 error:error];
+
+ if(doc == nil)
+ {
+ return nil;
+ }
+
+ DDXMLNode *result = [doc rootElement];
+ [result detach];
+ [doc release];
+
+ return [result retain];
+}
+
+ (id)nodeWithPrimitive:(xmlKindPtr)nodePtr
{
return [[[DDXMLElement alloc] initWithPrimitive:nodePtr] autorelease];
View
25 DDXMLTesting.m
@@ -28,6 +28,7 @@ + (void)testXPath;
+ (void)testNodesForXPath;
+ (void)testNSXMLBugs;
+ (void)testInsertChild;
++ (void)testElementSerialization;
@end
@implementation DDXMLTesting
@@ -60,6 +61,7 @@ + (void)performTests
[self testNodesForXPath];
[self testNSXMLBugs];
[self testInsertChild];
+ [self testElementSerialization];
[self tearDown];
}
@@ -1483,4 +1485,27 @@ + (void)testInsertChild
[pool release];
}
++ (void)testElementSerialization
+{
+ NSLog(@"Starting %@...", NSStringFromSelector(_cmd));
+ NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
+
+ NSString *str = @"<soup spicy=\"no\">chicken noodle</soup>";
+ NSError *err;
+
+ err = nil;
+ NSXMLElement *nse = [[[NSXMLElement alloc] initWithXMLString:str error:&err] autorelease];
+
+ NSAssert((nse != nil) && (err == nil), @"Failed CHECK 1");
+
+ err = nil;
+ DDXMLElement *dde = [[[DDXMLElement alloc] initWithXMLString:str error:&err] autorelease];
+
+ NSAssert((dde != nil) && (err == nil), @"Failed test 1");
+
+ NSAssert([[nse XMLString] isEqualToString:[dde XMLString]], @"Failed test 2");
+
+ [pool release];
+}
+
@end
Please sign in to comment.
Something went wrong with that request. Please try again.