Skip to content

Commit

Permalink
added kiss XML library
Browse files Browse the repository at this point in the history
  • Loading branch information
Mike Laurence authored and Mike Laurence committed Mar 19, 2010
1 parent 8180562 commit 3d90aeb
Show file tree
Hide file tree
Showing 15 changed files with 3,120 additions and 21 deletions.
26 changes: 14 additions & 12 deletions Examples/CoreTest/CoreTest.xcodeproj/mikelaurence.mode1v3
Expand Up @@ -267,6 +267,7 @@
<string>B568503D1100D03C00A4C816</string>
<string>B56851B41100D66D00A4C816</string>
<string>080E96DDFE201D6D7F000001</string>
<string>B5EED674113E2009004DAE9C</string>
<string>B5BAC04410FFE04600D57FCA</string>
<string>B5BAC0D610FFE1EF00D57FCA</string>
<string>29B97315FDCFA39411CA2CEA</string>
Expand All @@ -280,13 +281,14 @@
<key>PBXSmartGroupTreeModuleOutlineStateSelectionKey</key>
<array>
<array>
<integer>7</integer>
<integer>3</integer>
<integer>32</integer>
<integer>27</integer>
<integer>26</integer>
<integer>0</integer>
</array>
</array>
<key>PBXSmartGroupTreeModuleOutlineStateVisibleRectKey</key>
<string>{{0, 0}, {317, 904}}</string>
<string>{{0, 274}, {317, 904}}</string>
</dict>
<key>PBXTopSmartGroupGIDs</key>
<array/>
Expand Down Expand Up @@ -335,7 +337,7 @@
<key>_historyCapacity</key>
<integer>0</integer>
<key>bookmark</key>
<string>B55BE55B11536CA20059E974</string>
<string>B55D1F8C11540406009C8B4A</string>
<key>history</key>
<array>
<string>B56851741100D26100A4C816</string>
Expand Down Expand Up @@ -407,7 +409,7 @@
<string>B58014BF1153691D00DA5921</string>
<string>B58014DE115369E700DA5921</string>
<string>B55BE55911536CA20059E974</string>
<string>B55BE55A11536CA20059E974</string>
<string>B55BE55B11536CA20059E974</string>
</array>
</dict>
<key>SplitCount</key>
Expand All @@ -419,14 +421,14 @@
<key>GeometryConfiguration</key>
<dict>
<key>Frame</key>
<string>{{0, 0}, {1194, 863}}</string>
<string>{{0, 0}, {1194, 862}}</string>
<key>RubberWindowFrame</key>
<string>28 60 1533 963 0 0 1680 1028 </string>
</dict>
<key>Module</key>
<string>PBXNavigatorGroup</string>
<key>Proportion</key>
<string>863pt</string>
<string>862pt</string>
</dict>
<dict>
<key>ContentConfiguration</key>
Expand All @@ -439,14 +441,14 @@
<key>GeometryConfiguration</key>
<dict>
<key>Frame</key>
<string>{{0, 868}, {1194, 54}}</string>
<string>{{0, 867}, {1194, 55}}</string>
<key>RubberWindowFrame</key>
<string>28 60 1533 963 0 0 1680 1028 </string>
</dict>
<key>Module</key>
<string>XCDetailModule</string>
<key>Proportion</key>
<string>54pt</string>
<string>55pt</string>
</dict>
</array>
<key>Proportion</key>
Expand All @@ -465,9 +467,9 @@
</array>
<key>TableOfContents</key>
<array>
<string>B55BE55C11536CA20059E974</string>
<string>B55D1F89115403F2009C8B4A</string>
<string>1CE0B1FE06471DED0097A5F4</string>
<string>B55BE55D11536CA20059E974</string>
<string>B55D1F8A115403F2009C8B4A</string>
<string>1CE0B20306471E060097A5F4</string>
<string>1CE0B20506471E060097A5F4</string>
</array>
Expand Down Expand Up @@ -686,7 +688,7 @@
<key>TableOfContents</key>
<array>
<string>B5BAC03F10FFE02400D57FCA</string>
<string>B55BE55E11536CA20059E974</string>
<string>B55D1F8B115403F2009C8B4A</string>
<string>1CD0528F0623707200166675</string>
<string>XCMainBuildResultsModuleGUID</string>
</array>
Expand Down
36 changes: 29 additions & 7 deletions Examples/CoreTest/CoreTest.xcodeproj/mikelaurence.pbxuser
Expand Up @@ -101,14 +101,16 @@
PBXFileDataSource_Warnings_ColumnID,
);
};
PBXPerProjectTemplateStateSaveDate = 290679945;
PBXWorkspaceStateSaveDate = 290679945;
PBXPerProjectTemplateStateSaveDate = 290718696;
PBXWorkspaceStateSaveDate = 290718696;
};
perUserProjectItems = {
B52381A11148549900AB02EB = B52381A11148549900AB02EB /* PBXTextBookmark */;
B55BE55911536CA20059E974 /* PBXTextBookmark */ = B55BE55911536CA20059E974 /* PBXTextBookmark */;
B55BE55A11536CA20059E974 /* PBXTextBookmark */ = B55BE55A11536CA20059E974 /* PBXTextBookmark */;
B55BE55B11536CA20059E974 /* PBXTextBookmark */ = B55BE55B11536CA20059E974 /* PBXTextBookmark */;
B55BE55911536CA20059E974 = B55BE55911536CA20059E974 /* PBXTextBookmark */;
B55BE55A11536CA20059E974 = B55BE55A11536CA20059E974 /* PBXTextBookmark */;
B55BE55B11536CA20059E974 = B55BE55B11536CA20059E974 /* PBXTextBookmark */;
B55D1F88115403F2009C8B4A /* PBXTextBookmark */ = B55D1F88115403F2009C8B4A /* PBXTextBookmark */;
B55D1F8C11540406009C8B4A /* PBXTextBookmark */ = B55D1F8C11540406009C8B4A /* PBXTextBookmark */;
B55D27041151530D004F83F6 = B55D27041151530D004F83F6 /* PBXTextBookmark */;
B55D272D11515553004F83F6 = B55D272D11515553004F83F6 /* PBXTextBookmark */;
B55D272F115155AC004F83F6 = B55D272F115155AC004F83F6 /* PBXTextBookmark */;
Expand Down Expand Up @@ -252,6 +254,26 @@
vrLen = 1800;
vrLoc = 2464;
};
B55D1F88115403F2009C8B4A /* PBXTextBookmark */ = {
isa = PBXTextBookmark;
fRef = B56418A311064CBB00D1B038 /* CoreResourceTestCase.m */;
name = "CoreResourceTestCase.m: 113";
rLen = 0;
rLoc = 4186;
rType = 0;
vrLen = 1801;
vrLoc = 2463;
};
B55D1F8C11540406009C8B4A /* PBXTextBookmark */ = {
isa = PBXTextBookmark;
fRef = B56418A311064CBB00D1B038 /* CoreResourceTestCase.m */;
name = "CoreResourceTestCase.m: 83";
rLen = 0;
rLoc = 2859;
rType = 0;
vrLen = 1801;
vrLoc = 2463;
};
B55D26EB11514F25004F83F6 /* TestScript.sh */ = {
uiCtxt = {
sepNavIntBoundsRect = "{{0, 0}, {1133, 786}}";
Expand Down Expand Up @@ -544,8 +566,8 @@
B56418A311064CBB00D1B038 /* CoreResourceTestCase.m */ = {
uiCtxt = {
sepNavIntBoundsRect = "{{0, 0}, {1236, 2318}}";
sepNavSelRange = "{4186, 0}";
sepNavVisRange = "{2464, 1800}";
sepNavSelRange = "{2859, 0}";
sepNavVisRange = "{2463, 1801}";
};
};
B56418A511064CFA00D1B038 /* CoreResourceTestCase.h */ = {
Expand Down
3 changes: 1 addition & 2 deletions Examples/CoreTest/CoreTest.xcodeproj/project.pbxproj
Expand Up @@ -315,8 +315,7 @@
B560DF841150088B00BE843A /* NSStringAdditions.h */,
B560DF851150088B00BE843A /* NSStringAdditions.m */,
);
name = KissXML;
path = kissxml;
path = KissXML;
sourceTree = "<group>";
};
B568503D1100D03C00A4C816 /* Tests */ = {
Expand Down
3 changes: 3 additions & 0 deletions Libraries/KissXML/DDXML.h
@@ -0,0 +1,3 @@
#import "DDXMLNode.h"
#import "DDXMLElement.h"
#import "DDXMLDocument.h"
67 changes: 67 additions & 0 deletions Libraries/KissXML/DDXMLDocument.h
@@ -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
111 changes: 111 additions & 0 deletions Libraries/KissXML/DDXMLDocument.m
@@ -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

0 comments on commit 3d90aeb

Please sign in to comment.