OOTBXML.h
1 // ================================================================================================
2 // TBXML.h
3 // Fast processing of XML files
4 //
5 // ================================================================================================
6 // Created by Tom Bradley on 21/10/2009.
7 // Version 1.4
8 //
9 // Copyright (c) 2009 Tom Bradley
10 //
11 // Permission is hereby granted, free of charge, to any person obtaining a copy
12 // of this software and associated documentation files (the "Software"), to deal
13 // in the Software without restriction, including without limitation the rights
14 // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
15 // copies of the Software, and to permit persons to whom the Software is
16 // furnished to do so, subject to the following conditions:
17 //
18 // The above copyright notice and this permission notice shall be included in
19 // all copies or substantial portions of the Software.
20 //
21 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
22 // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
23 // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
24 // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
25 // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
26 // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
27 // THE SOFTWARE.
28 // ================================================================================================
29 
30 
31 // ================================================================================================
32 // Defines
33 // ================================================================================================
34 #define OO_TBXML_MAX_ELEMENTS 100
35 #define OO_TBXML_MAX_ATTRIBUTES 100
36 
37 #define OO_TBXML_ATTRIBUTE_NAME_START 0
38 #define OO_TBXML_ATTRIBUTE_NAME_END 1
39 #define OO_TBXML_ATTRIBUTE_VALUE_START 2
40 #define OO_TBXML_ATTRIBUTE_VALUE_END 3
41 #define OO_TBXML_ATTRIBUTE_CDATA_END 4
42 #import <Foundation/Foundation.h>
43 
44 
45 // ================================================================================================
46 // Structures
47 // ================================================================================================
48 typedef struct _OOTBXMLAttribute {
49  char * name;
50  char * value;
53 
54 typedef struct _OOTBXMLElement {
55  char * name;
56  char * text;
57 
59 
61 
64 
67 
69 
70 typedef struct _OOTBXMLElementBuffer {
75 
76 typedef struct _OOTBXMLAttributeBuffer {
81 
82 // ================================================================================================
83 // TBXML Public Interface
84 // ================================================================================================
85 @interface OOTBXML : NSObject {
86 
87 @private
88  OOTBXMLElement * rootXMLElement;
89 
90  OOTBXMLElementBuffer * currentElementBuffer;
91  OOTBXMLAttributeBuffer * currentAttributeBuffer;
92 
93  long currentElement;
94  long currentAttribute;
95 
96  char * bytes;
97  long bytesLength;
98  NSArray * ignoredTags;
99 }
100 
101 @property (nonatomic, readonly) OOTBXMLElement * rootXMLElement;
102 
103 + (id)tbxmlWithURL:(NSURL*)aURL;
104 + (id)tbxmlWithURL:(NSURL*)aURL ignoredTags:(NSArray *)theIgnoredTags;
105 + (id)tbxmlWithXMLString:(NSString*)aXMLString;
106 + (id)tbxmlWithXMLString:(NSString*)aXMLString ignoredTags:(NSArray *)theIgnoredTags;
107 + (id)tbxmlWithXMLData:(NSData*)aData;
108 + (id)tbxmlWithXMLData:(NSData*)aData ignoredTags:(NSArray *)theIgnoredTags;
109 + (id)tbxmlWithXMLFile:(NSString*)aXMLFile;
110 + (id)tbxmlWithXMLFile:(NSString*)aXMLFile ignoredTags:(NSArray *)theIgnoredTags;
111 + (id)tbxmlWithXMLFile:(NSString*)aXMLFile fileExtension:(NSString*)aFileExtension;
112 + (id)tbxmlWithXMLFile:(NSString*)aXMLFile fileExtension:(NSString*)aFileExtension ignoredTags:(NSArray *)theIgnoredTags;
113 
114 - (id)initWithURL:(NSURL*)aURL;
115 - (id)initWithURL:(NSURL*)aURL ignoredTags:(NSArray *)theIgnoredTags;
116 - (id)initWithXMLString:(NSString*)aXMLString;
117 - (id)initWithXMLString:(NSString*)aXMLString ignoredTags:(NSArray *)theIgnoredTags;
118 - (id)initWithXMLData:(NSData*)aData;
119 - (id)initWithXMLData:(NSData*)aData ignoredTags:(NSArray *)theIgnoredTags;
120 - (id)initWithXMLFile:(NSString*)aXMLFile;
121 - (id)initWithXMLFile:(NSString*)aXMLFile ignoredTags:(NSArray *)theIgnoredTags;
122 - (id)initWithXMLFile:(NSString*)aXMLFile fileExtension:(NSString*)aFileExtension;
123 - (id)initWithXMLFile:(NSString*)aXMLFile fileExtension:(NSString*)aFileExtension ignoredTags:(NSArray *)theIgnoredTags;
124 
125 @end
126 
127 // ================================================================================================
128 // TBXML Static Functions Interface
129 // ================================================================================================
130 
132 
133 + (NSString*) elementName:(OOTBXMLElement*)aXMLElement;
134 + (NSString*) textForElement:(OOTBXMLElement*)aXMLElement;
135 + (NSString*) valueOfAttributeNamed:(NSString *)aName forElement:(OOTBXMLElement*)aXMLElement;
136 
137 + (NSString*) attributeName:(OOTBXMLAttribute*)aXMLAttribute;
138 + (NSString*) attributeValue:(OOTBXMLAttribute*)aXMLAttribute;
139 
140 + (OOTBXMLElement*) nextSiblingNamed:(NSString*)aName searchFromElement:(OOTBXMLElement*)aXMLElement;
141 + (OOTBXMLElement*) childElementNamed:(NSString*)aName parentElement:(OOTBXMLElement*)aParentXMLElement;
142 
143 @end
struct _OOTBXMLAttributeBuffer * previous
Definition: OOTBXML.h:79
char * text
Definition: OOTBXML.h:56
Definition: OOTBXML.h:76
Definition: OOTBXML.h:85
char * name
Definition: OOTBXML.h:49
Definition: OOTBXML.h:54
char * value
Definition: OOTBXML.h:50
struct _OOTBXMLElement * nextSibling
Definition: OOTBXML.h:65
struct _OOTBXMLElement * previousSibling
Definition: OOTBXML.h:66
Definition: OOTBXML.h:70
Definition: OOTBXML.h:48
struct _OOTBXMLElementBuffer * previous
Definition: OOTBXML.h:73
struct _OOTBXMLElement * firstChild
Definition: OOTBXML.h:62
struct _OOTBXMLElement * parentElement
Definition: OOTBXML.h:60
struct _OOTBXMLElement * currentChild
Definition: OOTBXML.h:63
OOTBXMLAttribute * attributes
Definition: OOTBXML.h:77
OOTBXMLAttribute * firstAttribute
Definition: OOTBXML.h:58
OOTBXMLElement * elements
Definition: OOTBXML.h:71
char * name
Definition: OOTBXML.h:55
struct _OOTBXMLAttributeBuffer * next
Definition: OOTBXML.h:78
Definition: OOTBXML.h:131
struct _OOTBXMLElementBuffer * next
Definition: OOTBXML.h:72
struct _OOTBXMLAttribute * next
Definition: OOTBXML.h:51