2 * Copyright (c) 2008 Apple Inc. All rights reserved.
4 * @APPLE_LICENSE_HEADER_START@
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
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.
21 * @APPLE_LICENSE_HEADER_END@
24 Copyright (c) 1998-2007, Apple Inc. All rights reserved.
27 #if !defined(__COREFOUNDATION_CFXMLNODE__)
28 #define __COREFOUNDATION_CFXMLNODE__ 1
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>
39 kCFXMLNodeCurrentVersion
= 1
42 typedef const struct __CFXMLNode
* CFXMLNodeRef
;
43 typedef CFTreeRef CFXMLTreeRef
;
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).
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.
65 /* Type codes for the different possible XML nodes; this list may grow.*/
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
83 typedef CFIndex CFXMLNodeTypeCode
;
86 CFDictionaryRef attributes
;
87 CFArrayRef attributeOrder
;
93 CFStringRef dataString
;
94 } CFXMLProcessingInstructionInfo
;
98 CFStringEncoding encoding
;
103 CFStringRef publicID
;
107 CFXMLExternalID externalID
;
108 } CFXMLDocumentTypeInfo
;
111 CFXMLExternalID externalID
;
115 /* This is expected to change in future versions */
116 CFStringRef contentDescription
;
117 } CFXMLElementTypeDeclarationInfo
;
120 /* This is expected to change in future versions */
121 CFStringRef attributeName
;
122 CFStringRef typeString
;
123 CFStringRef defaultString
;
124 } CFXMLAttributeDeclarationInfo
;
127 CFIndex numberOfAttributes
;
128 CFXMLAttributeDeclarationInfo
*attributes
;
129 } CFXMLAttributeListDeclarationInfo
;
132 kCFXMLEntityTypeParameter
, /* Implies parsed, internal */
133 kCFXMLEntityTypeParsedInternal
,
134 kCFXMLEntityTypeParsedExternal
,
135 kCFXMLEntityTypeUnparsed
,
136 kCFXMLEntityTypeCharacter
138 typedef CFIndex CFXMLEntityTypeCode
;
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 */
148 CFXMLEntityTypeCode entityType
;
149 } CFXMLEntityReferenceInfo
;
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 *
172 CFTypeID
CFXMLNodeGetTypeID(void);
174 /* Creates a new node based on xmlType, dataString, and additionalInfoPtr. version (together with xmlType) determines the expected structure of additionalInfoPtr */
176 CFXMLNodeRef
CFXMLNodeCreate(CFAllocatorRef alloc
, CFXMLNodeTypeCode xmlType
, CFStringRef dataString
, const void *additionalInfoPtr
, CFIndex version
);
178 /* Creates a copy of origNode (which may not be NULL). */
180 CFXMLNodeRef
CFXMLNodeCreateCopy(CFAllocatorRef alloc
, CFXMLNodeRef origNode
);
183 CFXMLNodeTypeCode
CFXMLNodeGetTypeCode(CFXMLNodeRef node
);
186 CFStringRef
CFXMLNodeGetString(CFXMLNodeRef node
);
189 const void *CFXMLNodeGetInfoPtr(CFXMLNodeRef node
);
192 CFIndex
CFXMLNodeGetVersion(CFXMLNodeRef node
);
196 /* Creates a childless, parentless tree from node */
198 CFXMLTreeRef
CFXMLTreeCreateWithNode(CFAllocatorRef allocator
, CFXMLNodeRef node
);
200 /* Extracts and returns the node stored in xmlTree */
202 CFXMLNodeRef
CFXMLTreeGetNode(CFXMLTreeRef xmlTree
);
206 #endif /* ! __COREFOUNDATION_CFXMLNODE__ */