Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Mike Laurence
authored and
Mike Laurence
committed
Mar 19, 2010
1 parent
8180562
commit 3d90aeb
Showing
15 changed files
with
3,120 additions
and
21 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
#import "DDXMLNode.h" | ||
#import "DDXMLElement.h" | ||
#import "DDXMLDocument.h" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
#import <Foundation/Foundation.h> | ||
#import "DDXMLElement.h" | ||
#import "DDXMLNode.h" | ||
|
||
|
||
enum { | ||
DDXMLDocumentXMLKind = 0, | ||
DDXMLDocumentXHTMLKind, | ||
DDXMLDocumentHTMLKind, | ||
DDXMLDocumentTextKind | ||
}; | ||
typedef NSUInteger DDXMLDocumentContentKind; | ||
|
||
@interface DDXMLDocument : DDXMLNode | ||
{ | ||
} | ||
|
||
- (id)initWithXMLString:(NSString *)string options:(NSUInteger)mask error:(NSError **)error; | ||
//- (id)initWithContentsOfURL:(NSURL *)url options:(NSUInteger)mask error:(NSError **)error; | ||
- (id)initWithData:(NSData *)data options:(NSUInteger)mask error:(NSError **)error; | ||
//- (id)initWithRootElement:(DDXMLElement *)element; | ||
|
||
//+ (Class)replacementClassForClass:(Class)cls; | ||
|
||
//- (void)setCharacterEncoding:(NSString *)encoding; //primitive | ||
//- (NSString *)characterEncoding; //primitive | ||
|
||
//- (void)setVersion:(NSString *)version; | ||
//- (NSString *)version; | ||
|
||
//- (void)setStandalone:(BOOL)standalone; | ||
//- (BOOL)isStandalone; | ||
|
||
//- (void)setDocumentContentKind:(DDXMLDocumentContentKind)kind; | ||
//- (DDXMLDocumentContentKind)documentContentKind; | ||
|
||
//- (void)setMIMEType:(NSString *)MIMEType; | ||
//- (NSString *)MIMEType; | ||
|
||
//- (void)setDTD:(DDXMLDTD *)documentTypeDeclaration; | ||
//- (DDXMLDTD *)DTD; | ||
|
||
//- (void)setRootElement:(DDXMLNode *)root; | ||
- (DDXMLElement *)rootElement; | ||
|
||
//- (void)insertChild:(DDXMLNode *)child atIndex:(NSUInteger)index; | ||
|
||
//- (void)insertChildren:(NSArray *)children atIndex:(NSUInteger)index; | ||
|
||
//- (void)removeChildAtIndex:(NSUInteger)index; | ||
|
||
//- (void)setChildren:(NSArray *)children; | ||
|
||
//- (void)addChild:(DDXMLNode *)child; | ||
|
||
//- (void)replaceChildAtIndex:(NSUInteger)index withNode:(DDXMLNode *)node; | ||
|
||
- (NSData *)XMLData; | ||
- (NSData *)XMLDataWithOptions:(NSUInteger)options; | ||
|
||
//- (id)objectByApplyingXSLT:(NSData *)xslt arguments:(NSDictionary *)arguments error:(NSError **)error; | ||
//- (id)objectByApplyingXSLTString:(NSString *)xslt arguments:(NSDictionary *)arguments error:(NSError **)error; | ||
//- (id)objectByApplyingXSLTAtURL:(NSURL *)xsltURL arguments:(NSDictionary *)argument error:(NSError **)error; | ||
|
||
//- (BOOL)validateAndReturnError:(NSError **)error; | ||
|
||
@end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,111 @@ | ||
#import "DDXMLDocument.h" | ||
#import "NSStringAdditions.h" | ||
#import "DDXMLPrivate.h" | ||
|
||
|
||
@implementation DDXMLDocument | ||
|
||
/** | ||
* Returns a DDXML wrapper object for the given primitive node. | ||
* The given node MUST be non-NULL and of the proper type. | ||
* | ||
* If the wrapper object already exists, it is retained/autoreleased and returned. | ||
* Otherwise a new wrapper object is alloc/init/autoreleased and returned. | ||
**/ | ||
+ (id)nodeWithPrimitive:(xmlKindPtr)kindPtr | ||
{ | ||
// If a wrapper object already exists, the _private variable is pointing to it. | ||
|
||
xmlDocPtr doc = (xmlDocPtr)kindPtr; | ||
if(doc->_private == NULL) | ||
return [[[DDXMLDocument alloc] initWithCheckedPrimitive:kindPtr] autorelease]; | ||
else | ||
return [[((DDXMLDocument *)(doc->_private)) retain] autorelease]; | ||
} | ||
|
||
/** | ||
* Returns a DDXML wrapper object for the given primitive node. | ||
* The given node MUST be non-NULL and of the proper type. | ||
* | ||
* The given node is checked, meaning a wrapper object for it does not already exist. | ||
**/ | ||
- (id)initWithCheckedPrimitive:(xmlKindPtr)kindPtr | ||
{ | ||
self = [super initWithCheckedPrimitive:kindPtr]; | ||
return self; | ||
} | ||
|
||
/** | ||
* Initializes and returns a DDXMLDocument object created from an NSData object. | ||
* | ||
* Returns an initialized DDXMLDocument object, or nil if initialization fails | ||
* because of parsing errors or other reasons. | ||
**/ | ||
- (id)initWithXMLString:(NSString *)string options:(NSUInteger)mask error:(NSError **)error | ||
{ | ||
return [self initWithData:[string dataUsingEncoding:NSUTF8StringEncoding] options:mask error:error]; | ||
} | ||
|
||
/** | ||
* Initializes and returns a DDXMLDocument object created from an NSData object. | ||
* | ||
* Returns an initialized DDXMLDocument object, or nil if initialization fails | ||
* because of parsing errors or other reasons. | ||
**/ | ||
- (id)initWithData:(NSData *)data options:(NSUInteger)mask error:(NSError **)error | ||
{ | ||
if(data == nil || [data length] == 0) | ||
{ | ||
if(error) *error = [NSError errorWithDomain:@"DDXMLErrorDomain" code:0 userInfo:nil]; | ||
|
||
[self release]; | ||
return nil; | ||
} | ||
|
||
// Even though xmlKeepBlanksDefault(0) is called in DDXMLNode's initialize method, | ||
// it has been documented that this call seems to get reset on the iPhone: | ||
// http://code.google.com/p/kissxml/issues/detail?id=8 | ||
// | ||
// Therefore, we call it again here just to be safe. | ||
xmlKeepBlanksDefault(0); | ||
|
||
xmlDocPtr doc = xmlParseMemory([data bytes], [data length]); | ||
if(doc == NULL) | ||
{ | ||
if(error) *error = [NSError errorWithDomain:@"DDXMLErrorDomain" code:1 userInfo:nil]; | ||
|
||
[self release]; | ||
return nil; | ||
} | ||
|
||
return [self initWithCheckedPrimitive:(xmlKindPtr)doc]; | ||
} | ||
|
||
/** | ||
* Returns the root element of the receiver. | ||
**/ | ||
- (DDXMLElement *)rootElement | ||
{ | ||
xmlDocPtr doc = (xmlDocPtr)genericPtr; | ||
|
||
// doc->children is a list containing possibly comments, DTDs, etc... | ||
|
||
xmlNodePtr rootNode = xmlDocGetRootElement(doc); | ||
|
||
if(rootNode != NULL) | ||
return [DDXMLElement nodeWithPrimitive:(xmlKindPtr)rootNode]; | ||
else | ||
return nil; | ||
} | ||
|
||
- (NSData *)XMLData | ||
{ | ||
return [[self XMLString] dataUsingEncoding:NSUTF8StringEncoding]; | ||
} | ||
|
||
- (NSData *)XMLDataWithOptions:(NSUInteger)options | ||
{ | ||
return [[self XMLStringWithOptions:options] dataUsingEncoding:NSUTF8StringEncoding]; | ||
} | ||
|
||
@end |
Oops, something went wrong.