Permalink
Browse files

All the files

  • Loading branch information...
1 parent 1c20a12 commit 7b2eb0a9a888172beb753a544f790aab8f897862 arashpayan committed Jan 15, 2009
Showing with 1,479 additions and 0 deletions.
  1. +35 −0 APAttribute.h
  2. +50 −0 APAttribute.m
  3. +36 −0 APDocument.h
  4. +185 −0 APDocument.m
  5. +57 −0 APElement.h
  6. +254 −0 APElement.m
  7. +23 −0 APXML.h
  8. +165 −0 COPYING.LESSER
  9. +674 −0 COPYING.txt
View
@@ -0,0 +1,35 @@
+/*
+ Copyright 2009, Arash Payan (http://arashpayan.com)
+ This library is distributed under the terms of the GNU Lesser GPL.
+
+ This file is part of APXML.
+
+ APXML is free software: you can redistribute it and/or modify
+ it under the terms of the GNU Lesser General Public License as published by
+ the Free Software Foundation, either version 3 of the License, or
+ (at your option) any later version.
+
+ APXML is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public License
+ along with APXML. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#import <UIKit/UIKit.h>
+
+
+@interface APAttribute : NSObject {
+ NSString *name;
+ NSString *value;
+}
+
++ (id)attributeWithName:(NSString*)aName value:(NSString*)aValue;
+- (id)initWithName:(NSString*)aName value:(NSString*)aValue;
+
+@property (readonly) NSString *name;
+@property (readonly) NSString *value;
+
+@end
View
@@ -0,0 +1,50 @@
+/*
+ Copyright 2009, Arash Payan (http://arashpayan.com)
+ This library is distributed under the terms of the GNU Lesser GPL.
+
+ This file is part of APXML.
+
+ APXML is free software: you can redistribute it and/or modify
+ it under the terms of the GNU Lesser General Public License as published by
+ the Free Software Foundation, either version 3 of the License, or
+ (at your option) any later version.
+
+ APXML is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public License
+ along with APXML. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#import "APAttribute.h"
+
+
+@implementation APAttribute
+
+@synthesize name;
+@synthesize value;
+
++ (id)attributeWithName:(NSString*)aName value:(NSString*)aValue {
+ return [[[APAttribute alloc] initWithName:aName value:aValue] autorelease];
+}
+
+- (id)initWithName:(NSString*)aName value:(NSString*)aValue {
+ if (self = [super init])
+ {
+ name = [[NSString alloc] initWithString:aName];
+ value = [[NSString alloc] initWithString:aValue];
+ }
+
+ return self;
+}
+
+- (void)dealloc {
+ [name release];
+ [value release];
+
+ [super dealloc];
+}
+
+@end
View
@@ -0,0 +1,36 @@
+/*
+ Copyright 2009, Arash Payan (http://arashpayan.com)
+ This library is distributed under the terms of the GNU Lesser GPL.
+
+ This file is part of APXML.
+
+ APXML is free software: you can redistribute it and/or modify
+ it under the terms of the GNU Lesser General Public License as published by
+ the Free Software Foundation, either version 3 of the License, or
+ (at your option) any later version.
+
+ APXML is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public License
+ along with APXML. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#import <UIKit/UIKit.h>
+@class APElement;
+
+
+@interface APDocument : NSObject {
+ APElement *rootElement;
+}
+
++ (id)documentWithXMLString:(NSString*)anXMLString;
+- (id)initWithRootElement:(APElement*)aRootElement;
+- (id)initWithString:(NSString*)anXMLString;
+- (APElement*)rootElement;
+- (NSString*)prettyXML;
+- (NSString*)xml;
+
+@end
View
@@ -0,0 +1,185 @@
+/*
+ Copyright 2009, Arash Payan (http://arashpayan.com)
+ This library is distributed under the terms of the GNU Lesser GPL.
+
+ This file is part of APXML.
+
+ APXML is free software: you can redistribute it and/or modify
+ it under the terms of the GNU Lesser General Public License as published by
+ the Free Software Foundation, either version 3 of the License, or
+ (at your option) any later version.
+
+ APXML is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public License
+ along with APXML. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#import "APDocument.h"
+#import "APElement.h"
+
+@interface APXMLBuilder : NSObject
+{
+ APElement *rootElement;
+ APElement *openElement;
+ APElement *parentElement;
+}
+
+- (APElement*)rootElement;
+
+@end
+
+@implementation APXMLBuilder
+
+- (id)init {
+ if (self = [super init])
+ {
+ rootElement = nil;
+ openElement = nil;
+ parentElement = nil;
+ }
+
+ return self;
+}
+
+- (void)parserDidStartDocument:(NSXMLParser *)parser {
+
+}
+
+- (void)parserDidEndDocument:(NSXMLParser *)parser {
+
+}
+
+- (void)parser:(NSXMLParser *)parser didStartElement:(NSString *)elementName namespaceURI:(NSString *)namespaceURI qualifiedName:(NSString *)qualifiedName attributes:(NSDictionary *)attributeDict {
+ APElement *newElement = [APElement elementWithName:elementName attributes:attributeDict];
+ if (rootElement == nil)
+ rootElement = [newElement retain];
+
+ if (openElement != nil)
+ {
+ newElement.parent = openElement;
+ parentElement = openElement;
+ openElement = newElement;
+ }
+ else
+ {
+ newElement.parent = parentElement;
+ openElement = newElement;
+ }
+ if (parentElement != nil)
+ [parentElement addChild:openElement];
+}
+
+- (void)parser:(NSXMLParser *)parser didEndElement:(NSString *)elementName namespaceURI:(NSString *)namespaceURI qualifiedName:(NSString *)qName {
+ if (openElement != nil)
+ {
+ openElement = parentElement;
+ parentElement = parentElement.parent;
+ }
+}
+
+- (void)parser:(NSXMLParser *)parser parseErrorOccurred:(NSError *)parseError {
+
+}
+
+- (void)parser:(NSXMLParser *)parser validationErrorOccurred:(NSError *)validError {
+
+}
+
+- (void)parser:(NSXMLParser *)parser foundCharacters:(NSString *)string {
+ [openElement appendValue:string];
+}
+
+- (void)parser:(NSXMLParser *)parser foundIgnorableWhitespace:(NSString *)whitespaceString {
+}
+
+- (APElement*)rootElement {
+ return rootElement;
+}
+
+- (void) dealloc
+{
+ [rootElement release];
+
+ [super dealloc];
+}
+
+
+@end
+
+
+
+
+
+@implementation APDocument
+
++ (id)documentWithXMLString:(NSString*)anXMLString {
+ return [[[APDocument alloc] initWithString:anXMLString] autorelease];
+}
+
+- (id)initWithRootElement:(APElement*)aRootElement {
+ if (self = [super init])
+ {
+ rootElement = [aRootElement retain];
+ }
+
+ return self;
+}
+
+- (id)initWithString:(NSString*)anXMLString {
+ if (self = [super init])
+ {
+ APXMLBuilder *builder = [[APXMLBuilder alloc] init];
+ NSXMLParser *parser = [[NSXMLParser alloc] initWithData:[anXMLString dataUsingEncoding:NSUTF8StringEncoding]];
+ [parser setDelegate:builder];
+ [parser parse];
+
+ rootElement = [[builder rootElement] retain];
+
+ [builder release];
+ [parser release];
+ }
+
+ return self;
+}
+
+- (APElement*)rootElement {
+ return rootElement;
+}
+
+- (NSString*)prettyXML {
+ if (rootElement != nil)
+ {
+ NSMutableString *result = [[NSMutableString alloc] init];
+ [result appendString:@"<?xml version=\"1.0\" encoding=\"UTF-8\" ?>\n"];
+ [result appendString:[rootElement prettyXML:0]];
+ return result;
+ }
+ else
+ return nil;
+}
+
+- (NSString*)xml {
+ if (rootElement != nil)
+ {
+ NSMutableString *result = [[NSMutableString alloc] init];
+ [result appendString:@"<?xml version=\"1.0\" encoding=\"UTF-8\" ?>\n"];
+ [result appendString:[rootElement xml]];
+ return result;
+ }
+ else
+ return nil;
+}
+
+- (void) dealloc
+{
+ [rootElement release];
+
+ [super dealloc];
+}
+
+
+@end
View
@@ -0,0 +1,57 @@
+/*
+ Copyright 2009, Arash Payan (http://arashpayan.com)
+ This library is distributed under the terms of the GNU Lesser GPL.
+
+ This file is part of APXML.
+
+ APXML is free software: you can redistribute it and/or modify
+ it under the terms of the GNU Lesser General Public License as published by
+ the Free Software Foundation, either version 3 of the License, or
+ (at your option) any later version.
+
+ APXML is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public License
+ along with APXML. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#import <UIKit/UIKit.h>
+@class APAttribute;
+
+
+@interface APElement : NSObject {
+ NSString *name;
+ NSMutableString *value;
+ APElement *parent;
+
+ NSMutableDictionary *attributes;
+ NSMutableArray *childElements;
+}
+
+@property (readonly) NSString *name;
+@property (nonatomic, retain) APElement *parent;
+
++ (id)elementWithName:(NSString*)aName;
++ (id)elementWithName:(NSString*)aName attributes:(NSDictionary*)someAttributes;
+- (id)initWithName:(NSString*)aName;
+- (void)addAttribute:(APAttribute*)anAttribute;
+- (void)addAttributeNamed:(NSString*)aName withValue:(NSString*)aValue;
+- (void)addAttributes:(NSDictionary*)someAttributes;
+- (void)addChild:(APElement*)anElement;
+- (void)appendValue:(NSString*)aValue;
+- (int)attributeCount;
+- (int)childCount;
+- (NSArray*)childElements;
+- (NSMutableArray*)childElements:(NSString*)aName;
+- (APElement*)firstChildElement;
+- (APElement*)firstChildElementNamed:(NSString*)aName;
+- (NSString*)value;
+- (NSString*)valueForAttributeNamed:(NSString*)aName;
+- (NSString*)encodeEntities:(NSMutableString*)aString;
+- (NSString*)prettyXML:(int)tabs;
+- (NSString*)xml;
+
+@end
Oops, something went wrong.

0 comments on commit 7b2eb0a

Please sign in to comment.