]> git.saurik.com Git - apple/cf.git/blob - CFXMLNode.h
CF-476.17.tar.gz
[apple/cf.git] / CFXMLNode.h
1 /*
2 * Copyright (c) 2008 Apple Inc. All rights reserved.
3 *
4 * @APPLE_LICENSE_HEADER_START@
5 *
6 * This file contains Original Code and/or Modifications of Original Code
7 * as defined in and that are subject to the Apple Public Source License
8 * Version 2.0 (the 'License'). You may not use this file except in
9 * compliance with the License. Please obtain a copy of the License at
10 * http://www.opensource.apple.com/apsl/ and read it before using this
11 * file.
12 *
13 * The Original Code and all software distributed under the License are
14 * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
15 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
16 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
17 * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
18 * Please see the License for the specific language governing rights and
19 * limitations under the License.
20 *
21 * @APPLE_LICENSE_HEADER_END@
22 */
23 /* CFXMLNode.h
24 Copyright (c) 1998-2007, Apple Inc. All rights reserved.
25 */
26
27 #if !defined(__COREFOUNDATION_CFXMLNODE__)
28 #define __COREFOUNDATION_CFXMLNODE__ 1
29
30 #include <CoreFoundation/CFArray.h>
31 #include <CoreFoundation/CFDictionary.h>
32 #include <CoreFoundation/CFString.h>
33 #include <CoreFoundation/CFTree.h>
34 #include <CoreFoundation/CFURL.h>
35
36 CF_EXTERN_C_BEGIN
37
38 enum {
39 kCFXMLNodeCurrentVersion = 1
40 };
41
42 typedef const struct __CFXMLNode * CFXMLNodeRef;
43 typedef CFTreeRef CFXMLTreeRef;
44
45 /* An CFXMLNode describes an individual XML construct - like a tag, or a comment, or a string
46 of character data. Each CFXMLNode contains 3 main pieces of information - the node's type,
47 the data string, and a pointer to an additional data structure. The node's type ID is an enum
48 value of type CFXMLNodeTypeID. The data string is always a CFStringRef; the meaning of the
49 string is dependent on the node's type ID. The format of the additional data is also dependent
50 on the node's type; in general, there is a custom structure for each type that requires
51 additional data. See below for the mapping from type ID to meaning of the data string and
52 structure of the additional data. Note that these structures are versioned, and may change
53 as the parser changes. The current version can always be identified by kCFXMLNodeCurrentVersion;
54 earlier versions can be identified and used by passing earlier values for the version number
55 (although the older structures would have been removed from the header).
56
57 An CFXMLTree is simply a CFTree whose context data is known to be an CFXMLNodeRef. As
58 such, an CFXMLTree can be used to represent an entire XML document; the CFTree
59 provides the tree structure of the document, while the CFXMLNodes identify and describe
60 the nodes of the tree. An XML document can be parsed to a CFXMLTree, and a CFXMLTree
61 can generate the data for the equivalent XML document - see CFXMLParser.h for more
62 information on parsing XML.
63 */
64
65 /* Type codes for the different possible XML nodes; this list may grow.*/
66 enum {
67 kCFXMLNodeTypeDocument = 1,
68 kCFXMLNodeTypeElement = 2,
69 kCFXMLNodeTypeAttribute = 3,
70 kCFXMLNodeTypeProcessingInstruction = 4,
71 kCFXMLNodeTypeComment = 5,
72 kCFXMLNodeTypeText = 6,
73 kCFXMLNodeTypeCDATASection = 7,
74 kCFXMLNodeTypeDocumentFragment = 8,
75 kCFXMLNodeTypeEntity = 9,
76 kCFXMLNodeTypeEntityReference = 10,
77 kCFXMLNodeTypeDocumentType = 11,
78 kCFXMLNodeTypeWhitespace = 12,
79 kCFXMLNodeTypeNotation = 13,
80 kCFXMLNodeTypeElementTypeDeclaration = 14,
81 kCFXMLNodeTypeAttributeListDeclaration = 15
82 };
83 typedef CFIndex CFXMLNodeTypeCode;
84
85 typedef struct {
86 CFDictionaryRef attributes;
87 CFArrayRef attributeOrder;
88 Boolean isEmpty;
89 char _reserved[3];
90 } CFXMLElementInfo;
91
92 typedef struct {
93 CFStringRef dataString;
94 } CFXMLProcessingInstructionInfo;
95
96 typedef struct {
97 CFURLRef sourceURL;
98 CFStringEncoding encoding;
99 } CFXMLDocumentInfo;
100
101 typedef struct {
102 CFURLRef systemID;
103 CFStringRef publicID;
104 } CFXMLExternalID;
105
106 typedef struct {
107 CFXMLExternalID externalID;
108 } CFXMLDocumentTypeInfo;
109
110 typedef struct {
111 CFXMLExternalID externalID;
112 } CFXMLNotationInfo;
113
114 typedef struct {
115 /* This is expected to change in future versions */
116 CFStringRef contentDescription;
117 } CFXMLElementTypeDeclarationInfo;
118
119 typedef struct {
120 /* This is expected to change in future versions */
121 CFStringRef attributeName;
122 CFStringRef typeString;
123 CFStringRef defaultString;
124 } CFXMLAttributeDeclarationInfo;
125
126 typedef struct {
127 CFIndex numberOfAttributes;
128 CFXMLAttributeDeclarationInfo *attributes;
129 } CFXMLAttributeListDeclarationInfo;
130
131 enum {
132 kCFXMLEntityTypeParameter, /* Implies parsed, internal */
133 kCFXMLEntityTypeParsedInternal,
134 kCFXMLEntityTypeParsedExternal,
135 kCFXMLEntityTypeUnparsed,
136 kCFXMLEntityTypeCharacter
137 };
138 typedef CFIndex CFXMLEntityTypeCode;
139
140 typedef struct {
141 CFXMLEntityTypeCode entityType;
142 CFStringRef replacementText; /* NULL if entityType is external or unparsed */
143 CFXMLExternalID entityID; /* entityID.systemID will be NULL if entityType is internal */
144 CFStringRef notationName; /* NULL if entityType is parsed */
145 } CFXMLEntityInfo;
146
147 typedef struct {
148 CFXMLEntityTypeCode entityType;
149 } CFXMLEntityReferenceInfo;
150
151 /*
152 dataTypeCode meaning of dataString format of infoPtr
153 =========== ===================== =================
154 kCFXMLNodeTypeDocument <currently unused> CFXMLDocumentInfo *
155 kCFXMLNodeTypeElement tag name CFXMLElementInfo *
156 kCFXMLNodeTypeAttribute <currently unused> <currently unused>
157 kCFXMLNodeTypeProcessingInstruction name of the target CFXMLProcessingInstructionInfo *
158 kCFXMLNodeTypeComment text of the comment NULL
159 kCFXMLNodeTypeText the text's contents NULL
160 kCFXMLNodeTypeCDATASection text of the CDATA NULL
161 kCFXMLNodeTypeDocumentFragment <currently unused> <currently unused>
162 kCFXMLNodeTypeEntity name of the entity CFXMLEntityInfo *
163 kCFXMLNodeTypeEntityReference name of the referenced entity CFXMLEntityReferenceInfo *
164 kCFXMLNodeTypeDocumentType name given as top-level element CFXMLDocumentTypeInfo *
165 kCFXMLNodeTypeWhitespace text of the whitespace NULL
166 kCFXMLNodeTypeNotation notation name CFXMLNotationInfo *
167 kCFXMLNodeTypeElementTypeDeclaration tag name CFXMLElementTypeDeclarationInfo *
168 kCFXMLNodeTypeAttributeListDeclaration tag name CFXMLAttributeListDeclarationInfo *
169 */
170
171 CF_EXPORT
172 CFTypeID CFXMLNodeGetTypeID(void);
173
174 /* Creates a new node based on xmlType, dataString, and additionalInfoPtr. version (together with xmlType) determines the expected structure of additionalInfoPtr */
175 CF_EXPORT
176 CFXMLNodeRef CFXMLNodeCreate(CFAllocatorRef alloc, CFXMLNodeTypeCode xmlType, CFStringRef dataString, const void *additionalInfoPtr, CFIndex version);
177
178 /* Creates a copy of origNode (which may not be NULL). */
179 CF_EXPORT
180 CFXMLNodeRef CFXMLNodeCreateCopy(CFAllocatorRef alloc, CFXMLNodeRef origNode);
181
182 CF_EXPORT
183 CFXMLNodeTypeCode CFXMLNodeGetTypeCode(CFXMLNodeRef node);
184
185 CF_EXPORT
186 CFStringRef CFXMLNodeGetString(CFXMLNodeRef node);
187
188 CF_EXPORT
189 const void *CFXMLNodeGetInfoPtr(CFXMLNodeRef node);
190
191 CF_EXPORT
192 CFIndex CFXMLNodeGetVersion(CFXMLNodeRef node);
193
194 /* CFXMLTreeRef */
195
196 /* Creates a childless, parentless tree from node */
197 CF_EXPORT
198 CFXMLTreeRef CFXMLTreeCreateWithNode(CFAllocatorRef allocator, CFXMLNodeRef node);
199
200 /* Extracts and returns the node stored in xmlTree */
201 CF_EXPORT
202 CFXMLNodeRef CFXMLTreeGetNode(CFXMLTreeRef xmlTree);
203
204 CF_EXTERN_C_END
205
206 #endif /* ! __COREFOUNDATION_CFXMLNODE__ */
207