-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathDDXMLNode.h
170 lines (124 loc) · 4.89 KB
/
DDXMLNode.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
#import <Foundation/Foundation.h>
#import <libxml/tree.h>
@class DDXMLDocument;
enum {
DDXMLInvalidKind = 0,
DDXMLDocumentKind = XML_DOCUMENT_NODE,
DDXMLElementKind = XML_ELEMENT_NODE,
DDXMLAttributeKind = XML_ATTRIBUTE_NODE,
DDXMLNamespaceKind = XML_NAMESPACE_DECL,
DDXMLProcessingInstructionKind = XML_PI_NODE,
DDXMLCommentKind = XML_COMMENT_NODE,
DDXMLTextKind = XML_TEXT_NODE,
DDXMLDTDKind = XML_DTD_NODE,
DDXMLEntityDeclarationKind = XML_ENTITY_DECL,
DDXMLAttributeDeclarationKind = XML_ATTRIBUTE_DECL,
DDXMLElementDeclarationKind = XML_ELEMENT_DECL,
DDXMLNotationDeclarationKind = XML_NOTATION_NODE
};
typedef NSUInteger DDXMLNodeKind;
enum {
DDXMLNodeOptionsNone = 0,
DDXMLNodeExpandEmptyElement = 1 << 1,
DDXMLNodeCompactEmptyElement = 1 << 2,
DDXMLNodePrettyPrint = 1 << 17,
};
/**
* DDXMLNode can represent several underlying types, such as xmlNodePtr, xmlDocPtr, xmlAttrPtr, xmlNsPtr, etc.
* All of these are pointers to structures, and all of those structures start with a pointer, and a type.
* The xmlKind struct is used as a generic structure, and a stepping stone.
* We use it to check the type of a structure, and then perform the appropriate cast.
*
* For example:
* if(genericPtr->type == XML_ATTRIBUTE_NODE)
* {
* xmlAttrPtr attr = (xmlAttrPtr)genericPtr;
* // Do something with attr
* }
**/
struct _xmlKind {
void * ignore;
xmlElementType type;
};
typedef struct _xmlKind *xmlKindPtr;
/**
* Most xml types all start with this standard structure. In fact, all do except the xmlNsPtr.
* We will occasionally take advantage of this to simplify code when the code wouldn't vary from type to type.
* Obviously, you cannnot cast a xmlNsPtr to a xmlStdPtr.
**/
struct _xmlStd {
void * _private;
xmlElementType type;
const xmlChar *name;
struct _xmlNode *children;
struct _xmlNode *last;
struct _xmlNode *parent;
struct _xmlStd *next;
struct _xmlStd *prev;
struct _xmlDoc *doc;
};
typedef struct _xmlStd *xmlStdPtr;
@interface DDXMLNode : NSObject <NSCopying>
{
// Every DDXML object is simply a wrapper around an underlying libxml node
xmlKindPtr genericPtr;
// The xmlNsPtr type doesn't store a reference to it's parent
// This is here to fix that problem, and make this class more compatible with the NSXML classes
xmlNodePtr nsParentPtr;
}
//- (id)initWithKind:(DDXMLNodeKind)kind;
//- (id)initWithKind:(DDXMLNodeKind)kind options:(NSUInteger)options;
//+ (id)document;
//+ (id)documentWithRootElement:(DDXMLElement *)element;
+ (id)elementWithName:(NSString *)name;
+ (id)elementWithName:(NSString *)name URI:(NSString *)URI;
+ (id)elementWithName:(NSString *)name stringValue:(NSString *)string;
+ (id)elementWithName:(NSString *)name children:(NSArray *)children attributes:(NSArray *)attributes;
+ (id)attributeWithName:(NSString *)name stringValue:(NSString *)stringValue;
+ (id)attributeWithName:(NSString *)name URI:(NSString *)URI stringValue:(NSString *)stringValue;
+ (id)namespaceWithName:(NSString *)name stringValue:(NSString *)stringValue;
+ (id)processingInstructionWithName:(NSString *)name stringValue:(NSString *)stringValue;
+ (id)commentWithStringValue:(NSString *)stringValue;
+ (id)textWithStringValue:(NSString *)stringValue;
//+ (id)DTDNodeWithXMLString:(NSString *)string;
#pragma mark --- Properties ---
- (DDXMLNodeKind)kind;
- (void)setName:(NSString *)name;
- (NSString *)name;
//- (void)setObjectValue:(id)value;
//- (id)objectValue;
- (void)setStringValue:(NSString *)string;
//- (void)setStringValue:(NSString *)string resolvingEntities:(BOOL)resolve;
- (NSString *)stringValue;
#pragma mark --- Tree Navigation ---
- (NSUInteger)index;
- (NSUInteger)level;
- (DDXMLDocument *)rootDocument;
- (DDXMLNode *)parent;
- (NSUInteger)childCount;
- (NSArray *)children;
- (DDXMLNode *)childAtIndex:(NSUInteger)index;
- (DDXMLNode *)previousSibling;
- (DDXMLNode *)nextSibling;
- (DDXMLNode *)previousNode;
- (DDXMLNode *)nextNode;
- (void)detach;
- (NSString *)XPath;
#pragma mark --- QNames ---
- (NSString *)localName;
- (NSString *)prefix;
- (void)setURI:(NSString *)URI;
- (NSString *)URI;
+ (NSString *)localNameForName:(NSString *)name;
+ (NSString *)prefixForName:(NSString *)name;
//+ (DDXMLNode *)predefinedNamespaceForPrefix:(NSString *)name;
#pragma mark --- Output ---
- (NSString *)description;
- (NSString *)XMLString;
- (NSString *)XMLStringWithOptions:(NSUInteger)options;
//- (NSString *)canonicalXMLStringPreservingComments:(BOOL)comments;
#pragma mark --- XPath/XQuery ---
- (NSArray *)nodesForXPath:(NSString *)xpath error:(NSError **)error;
//- (NSArray *)objectsForXQuery:(NSString *)xquery constants:(NSDictionary *)constants error:(NSError **)error;
//- (NSArray *)objectsForXQuery:(NSString *)xquery error:(NSError **)error;
@end