1 |
|
---|
2 | /*
|
---|
3 | *@@sourcefile xml.h:
|
---|
4 | * header file for xml.c (XML parsing).
|
---|
5 | *
|
---|
6 | * See remarks there.
|
---|
7 | *
|
---|
8 | *@@added V0.9.6 (2000-10-29) [umoeller]
|
---|
9 | *@@include #include <os2.h>
|
---|
10 | *@@include #include "expat\expat.h" // must come before xml.h
|
---|
11 | *@@include #include "helpers\linklist.h"
|
---|
12 | *@@include #include "helpers\tree.h"
|
---|
13 | *@@include #include "helpers\xstring.h"
|
---|
14 | *@@include #include "helpers\xml.h"
|
---|
15 | */
|
---|
16 |
|
---|
17 | #if __cplusplus
|
---|
18 | extern "C" {
|
---|
19 | #endif
|
---|
20 |
|
---|
21 | #ifndef XML_HEADER_INCLUDED
|
---|
22 | #define XML_HEADER_INCLUDED
|
---|
23 |
|
---|
24 | // define some basic things to make this work even with standard C
|
---|
25 | #if (!defined OS2_INCLUDED) && (!defined _OS2_H) && (!defined __SIMPLES_DEFINED) // changed V0.9.0 (99-10-22) [umoeller]
|
---|
26 | typedef unsigned long BOOL;
|
---|
27 | typedef unsigned long ULONG;
|
---|
28 | typedef unsigned char *PSZ;
|
---|
29 | #define TRUE (BOOL)1
|
---|
30 | #define FALSE (BOOL)0
|
---|
31 |
|
---|
32 | #ifdef __IBMCPP__ // added V0.9.0 (99-10-22) [umoeller]
|
---|
33 | #define APIENTRY _System
|
---|
34 | #endif
|
---|
35 |
|
---|
36 | #define __SIMPLES_DEFINED
|
---|
37 | #endif
|
---|
38 |
|
---|
39 | /* ******************************************************************
|
---|
40 | *
|
---|
41 | * Error handling
|
---|
42 | *
|
---|
43 | ********************************************************************/
|
---|
44 |
|
---|
45 | // ERROR_XML_FIRST is defined in expat\expat.h;
|
---|
46 | // the range up to ERROR_XML_FIRST + 24 is used
|
---|
47 | // by expat
|
---|
48 |
|
---|
49 | // START MATCHING ERROR MESSAGES (xmlDescribeError)
|
---|
50 | // validity errors:
|
---|
51 | #define ERROR_DOM_UNDECLARED_ELEMENT (ERROR_XML_FIRST + 24)
|
---|
52 | // invalidity: element is undeclared
|
---|
53 | #define ERROR_DOM_ROOT_ELEMENT_MISNAMED (ERROR_XML_FIRST + 25)
|
---|
54 | #define ERROR_DOM_INVALID_ROOT_ELEMENT (ERROR_XML_FIRST + 26)
|
---|
55 | #define ERROR_DOM_INVALID_SUBELEMENT (ERROR_XML_FIRST + 27)
|
---|
56 | // subelement may not appear in its parent element
|
---|
57 | #define ERROR_DOM_DUPLICATE_ELEMENT_DECL (ERROR_XML_FIRST + 28)
|
---|
58 | // more than one declaration for an element type
|
---|
59 | #define ERROR_DOM_DUPLICATE_ATTRIBUTE_DECL (ERROR_XML_FIRST + 29)
|
---|
60 | // more than one declaration for an attribute type
|
---|
61 | #define ERROR_DOM_UNDECLARED_ATTRIBUTE (ERROR_XML_FIRST + 30)
|
---|
62 | #define ERROR_ELEMENT_CANNOT_HAVE_CONTENT (ERROR_XML_FIRST + 31)
|
---|
63 | // element was declared "empty" and contains text anyway,
|
---|
64 | // or was declared "children" and contains something other
|
---|
65 | // than whitespace
|
---|
66 | #define ERROR_DOM_INVALID_ATTRIB_VALUE (ERROR_XML_FIRST + 32)
|
---|
67 | #define ERROR_DOM_REQUIRED_ATTRIBUTE_MISSING (ERROR_XML_FIRST + 33)
|
---|
68 | #define ERROR_DOM_SUBELEMENT_IN_EMPTY_ELEMENT (ERROR_XML_FIRST + 34)
|
---|
69 | // END MATCHING ERROR MESSAGES (xmlDescribeError)
|
---|
70 |
|
---|
71 | // error categories:
|
---|
72 | #define ERROR_DOM_PARSING (ERROR_XML_FIRST + 35)
|
---|
73 | #define ERROR_DOM_VALIDITY (ERROR_XML_FIRST + 36)
|
---|
74 |
|
---|
75 | // additional DOM errors
|
---|
76 | #define ERROR_DOM_NODETYPE_NOT_SUPPORTED (ERROR_XML_FIRST + 37)
|
---|
77 | // invalid node type in xmlCreateDomNode
|
---|
78 | #define ERROR_DOM_NO_DOCUMENT (ERROR_XML_FIRST + 38)
|
---|
79 | // cannot find document node
|
---|
80 | #define ERROR_DOM_NO_ELEMENT (ERROR_XML_FIRST + 39)
|
---|
81 | #define ERROR_DOM_DUPLICATE_DOCTYPE (ERROR_XML_FIRST + 40)
|
---|
82 | #define ERROR_DOM_DOCTYPE_ROOT_NAMES_MISMATCH (ERROR_XML_FIRST + 41)
|
---|
83 | // DOCTYPE is given and root element name does not match doctype name
|
---|
84 | #define ERROR_DOM_INTEGRITY (ERROR_XML_FIRST + 42)
|
---|
85 | #define ERROR_DOM_DUPLICATE_ATTRIBUTE (ERROR_XML_FIRST + 43)
|
---|
86 |
|
---|
87 | #define ERROR_DOM_VALIDATE_INVALID_ELEMENT (ERROR_XML_FIRST + 44)
|
---|
88 | #define ERROR_DOM_ELEMENT_DECL_OUTSIDE_DOCTYPE (ERROR_XML_FIRST + 45)
|
---|
89 | #define ERROR_DOM_ATTLIST_DECL_OUTSIDE_DOCTYPE (ERROR_XML_FIRST + 46)
|
---|
90 |
|
---|
91 | #define ERROR_DOM_INCOMPLETE_ENCODING_MAP (ERROR_XML_FIRST + 47)
|
---|
92 | // callback to UnknownEncodingHandler has provided
|
---|
93 | // an incomplete encoding map V0.9.14 (2001-08-09) [umoeller]
|
---|
94 |
|
---|
95 | #define ERROR_DOM_INVALID_EXTERNAL_HANDLER (ERROR_XML_FIRST + 48)
|
---|
96 |
|
---|
97 | #define ERROR_XML_LAST (ERROR_XML_FIRST + 48)
|
---|
98 |
|
---|
99 | const char* xmlDescribeError(int code);
|
---|
100 |
|
---|
101 | /* ******************************************************************
|
---|
102 | *
|
---|
103 | * Most basic node management
|
---|
104 | *
|
---|
105 | ********************************************************************/
|
---|
106 |
|
---|
107 | // content model node types:
|
---|
108 | typedef enum _NODEBASETYPE
|
---|
109 | {
|
---|
110 | TYPE_UNKNOWN,
|
---|
111 |
|
---|
112 | DOMNODE_ELEMENT, // node is a DOM ELEMENT
|
---|
113 | DOMNODE_ATTRIBUTE, // node is a DOM ATTRIBUTE
|
---|
114 | DOMNODE_TEXT, // node is a DOM TEXT node
|
---|
115 | // DOMNODE_CDATA_SECTION 4
|
---|
116 | // DOMNODE_ENTITY_REFERENCE 5
|
---|
117 | // DOMNODE_ENTITY 6
|
---|
118 | DOMNODE_PROCESSING_INSTRUCTION, // node is a DOM PI
|
---|
119 | DOMNODE_COMMENT, // node is a DOM COMMENT
|
---|
120 | DOMNODE_DOCUMENT, // node is a DOM document
|
---|
121 | DOMNODE_DOCUMENT_TYPE, // node is a DOM DOCUMENTTYPE
|
---|
122 | // #define DOMNODE_DOCUMENT_FRAGMENT 11
|
---|
123 | // #define DOMNODE_NOTATION 12
|
---|
124 |
|
---|
125 | // the following are all CMELEMENTPARTICLE nodes
|
---|
126 | ELEMENTPARTICLE_EMPTY,
|
---|
127 | ELEMENTPARTICLE_ANY,
|
---|
128 | ELEMENTPARTICLE_MIXED,
|
---|
129 | ELEMENTPARTICLE_CHOICE,
|
---|
130 | ELEMENTPARTICLE_SEQ,
|
---|
131 | ELEMENTPARTICLE_NAME,
|
---|
132 |
|
---|
133 | ATTRIBUTE_DECLARATION_BASE, // node is a CMATTRIBUTEDECLBASE
|
---|
134 | ATTRIBUTE_DECLARATION, // node is a CMATTRIBUTEDECL
|
---|
135 | ATTRIBUTE_DECLARATION_ENUM // node is a plain NODEBASE, part of an attr value enum
|
---|
136 | } NODEBASETYPE;
|
---|
137 |
|
---|
138 | /*
|
---|
139 | *@@ NODEBASE:
|
---|
140 | * root class of all nodes used in the
|
---|
141 | * DOM tree.
|
---|
142 | *
|
---|
143 | * The first item is a TREE to make this insertable
|
---|
144 | * into string maps via the functions in tree.c.
|
---|
145 | *
|
---|
146 | * A NODEBASE is also the first member of a DOMNODE
|
---|
147 | * so this is effectively a simulation of inheritance
|
---|
148 | * in plain C... DOMNODE inherits from NODEBASE,
|
---|
149 | * and some other types inherit from DOMNODE.
|
---|
150 | *
|
---|
151 | * This contains the node name, which is also used
|
---|
152 | * by the DOMNODE's (e.g. for element names).
|
---|
153 | * However, only DOMNODE defines the node value
|
---|
154 | * string.
|
---|
155 | *
|
---|
156 | *@@added V0.9.9 (2001-02-14) [umoeller]
|
---|
157 | */
|
---|
158 |
|
---|
159 | typedef struct _NODEBASE
|
---|
160 | {
|
---|
161 | TREE Tree; // tree.c
|
---|
162 | // ulKey simply points to the strNodeName
|
---|
163 | // member always V0.9.13 (2001-06-27) [umoeller]
|
---|
164 |
|
---|
165 | NODEBASETYPE ulNodeType; // class type; this is precious,
|
---|
166 | // all xml* functions make assumptions
|
---|
167 | // from this value
|
---|
168 |
|
---|
169 | XSTRING strNodeName;
|
---|
170 | // node name;
|
---|
171 | // -- for the various DOMNODE_* items, see _DOMNODE;
|
---|
172 | // -- for CMELEMENTPARTICLE nodes, this is the particle's name
|
---|
173 | // -- for CMELEMENTDECLNODE nodes, element name being declared
|
---|
174 | // -- for CMATTRIBUTEDECLBASE nodes, name of element to which this
|
---|
175 | // attrib decl belongs
|
---|
176 | // -- for CMATTRIBUTEDECL nodes, name of attribute;
|
---|
177 | // -- for ATTRIBUTE_DECLARATION_ENUM, attribute value in the
|
---|
178 | // possible values list.
|
---|
179 |
|
---|
180 | } NODEBASE, *PNODEBASE;
|
---|
181 |
|
---|
182 | /* ******************************************************************
|
---|
183 | *
|
---|
184 | * DOM level 1
|
---|
185 | *
|
---|
186 | ********************************************************************/
|
---|
187 |
|
---|
188 | /*
|
---|
189 | *@@ DOMNODE:
|
---|
190 | * this represents one @DOM node in an @XML document.
|
---|
191 | *
|
---|
192 | * The document itself is represented by a node with the
|
---|
193 | * DOMNODE_DOCUMENT type, which is the root of a tree as
|
---|
194 | * shown with xmlParse.
|
---|
195 | *
|
---|
196 | * The contents of the members vary according
|
---|
197 | * to ulNodeType (0 specifies that the field does not
|
---|
198 | * apply to that type).
|
---|
199 | *
|
---|
200 | * The first member of a DOMNODE is a NODEBASE to allow
|
---|
201 | * inserting these things in a tree. NODEBASE.ulNodeType
|
---|
202 | * _always_ specifies the various types that are using
|
---|
203 | * that structure to allow for type-safety (if we watch out).
|
---|
204 | * This is for faking inheritance.
|
---|
205 | *
|
---|
206 | * Note that we also implement specialized sub-structures of
|
---|
207 | * DOMNODE, whose first member is the DOMNODE (and therefore
|
---|
208 | * a NODEBASE as well):
|
---|
209 | *
|
---|
210 | * -- DOCUMENT nodes are given a _DOMDOCUMENTNODE structure.
|
---|
211 | *
|
---|
212 | * -- DOCTYPE nodes are given a _DOMDOCTYPENODE structure.
|
---|
213 | *
|
---|
214 | * Overview of member fields usage:
|
---|
215 | +
|
---|
216 | + ulNodeType | strNodeName | strNodeValue | llChildren | AttributesMap
|
---|
217 | + (NODEBASE) | (NODEBASE) | (DOMNODE) | (DOMNODE) | (DOMNODE)
|
---|
218 | + =======================================================================
|
---|
219 | + | | | |
|
---|
220 | + DOCUMENT | name from | 0 | 1 root | 0
|
---|
221 | + | DOCTYPE or | | ELEMENT |
|
---|
222 | + | NULL | | |
|
---|
223 | + | | | |
|
---|
224 | + --------------+-------------+--------------+------------+--------------
|
---|
225 | + | | | |
|
---|
226 | + ELEMENT | tag name | 0 | ELEMENT | ATTRIBUTE
|
---|
227 | + | | | nodes | nodes
|
---|
228 | + | | | |
|
---|
229 | + --------------+-------------+--------------+------------+--------------
|
---|
230 | + | | | |
|
---|
231 | + ATTRIBUTE | attribute | attribute | 0 | 0
|
---|
232 | + | name | value | |
|
---|
233 | + | | | |
|
---|
234 | + --------------+-------------+--------------+------------+--------------
|
---|
235 | + | | | |
|
---|
236 | + TEXT | 0 | text | 0 | 0
|
---|
237 | + | | contents | |
|
---|
238 | + | | | |
|
---|
239 | + --------------+-------------+--------------+------------+--------------
|
---|
240 | + | | | |
|
---|
241 | + COMMENT | 0 | comment | 0 | 0
|
---|
242 | + | | contents | |
|
---|
243 | + | | | |
|
---|
244 | + --------------+-------------+--------------+------------+--------------
|
---|
245 | + | | | |
|
---|
246 | + PI | PI target | PI data | 0 | 0
|
---|
247 | + | | | |
|
---|
248 | + | | | |
|
---|
249 | + --------------+-------------+--------------+------------+--------------
|
---|
250 | + | | | |
|
---|
251 | + DOCTYPE | doctype | | 0 | 0
|
---|
252 | + | name | | |
|
---|
253 | + | | | |
|
---|
254 | +
|
---|
255 | * The xwphelpers implementation does not implement CDATA sections,
|
---|
256 | * for which we have no need because @expat properly converts these
|
---|
257 | * into plain @content.
|
---|
258 | *
|
---|
259 | * In addition, W3C DOM specifies that the "node name" members contain
|
---|
260 | * "#document", "#text", and "#comment" strings for DOCUMENT,
|
---|
261 | * TEXT, and COMMENT nodes, respectively. I see no point in this other
|
---|
262 | * than consuming memory, so these fields are empty with this implementation.
|
---|
263 | */
|
---|
264 |
|
---|
265 | typedef struct _DOMNODE
|
---|
266 | {
|
---|
267 | NODEBASE NodeBase;
|
---|
268 |
|
---|
269 | PXSTRING pstrNodeValue; // ptr is NULL if none
|
---|
270 |
|
---|
271 | struct _DOMNODE *pParentNode;
|
---|
272 | // the parent node;
|
---|
273 | // NULL for DOCUMENT, DOCUMENT_FRAGMENT.
|
---|
274 | // The DOM spec says that attribs have no parent,
|
---|
275 | // but even though the attribute is not added to
|
---|
276 | // the "children" list of an element (but to the
|
---|
277 | // attributes map instead), we specify the element
|
---|
278 | // as the attribute's parent here.
|
---|
279 |
|
---|
280 | struct _DOMNODE *pDocumentNode;
|
---|
281 | // the document node, unless this is a DOCUMENT in itself.
|
---|
282 |
|
---|
283 | LINKLIST llChildren; // of DOMNODE* pointers, no auto-free
|
---|
284 |
|
---|
285 | TREE *AttributesMap; // of DOMNODE* pointers
|
---|
286 |
|
---|
287 | } DOMNODE, *PDOMNODE;
|
---|
288 |
|
---|
289 | /*
|
---|
290 | *@@ DOMDOCTYPENODE:
|
---|
291 | * specific _DOMNODE replacement structure which
|
---|
292 | * is used for DOCTYPE nodes.
|
---|
293 | *
|
---|
294 | * The DOMDOCTYPENODE is special (other than having
|
---|
295 | * extra fields) in that it is stored both in
|
---|
296 | * the document node's children list and in its
|
---|
297 | * pDocType field.
|
---|
298 | *
|
---|
299 | * DOMNODE.pstrNodeName is set to the name in the
|
---|
300 | * DOCTYPE statement by xmlCreateDocumentTypeNode,
|
---|
301 | * or is NULL if there's no DOCTYPE.
|
---|
302 | *
|
---|
303 | *@@added V0.9.9 (2001-02-14) [umoeller]
|
---|
304 | */
|
---|
305 |
|
---|
306 | typedef struct _DOMDOCTYPENODE
|
---|
307 | {
|
---|
308 | DOMNODE DomNode;
|
---|
309 |
|
---|
310 | XSTRING strPublicID;
|
---|
311 | XSTRING strSystemID;
|
---|
312 |
|
---|
313 | BOOL fHasInternalSubset;
|
---|
314 |
|
---|
315 | TREE *ElementDeclsTree;
|
---|
316 | // tree with pointers to _CMELEMENTDECLNODE nodes
|
---|
317 |
|
---|
318 | TREE *AttribDeclBasesTree;
|
---|
319 | // tree with pointers to _CMATTRIBUTEDECLBASE nodes
|
---|
320 |
|
---|
321 | } DOMDOCTYPENODE, *PDOMDOCTYPENODE;
|
---|
322 |
|
---|
323 | /*
|
---|
324 | *@@ DOMDOCUMENTNODE:
|
---|
325 | * specific _DOMNODE replacement structure which
|
---|
326 | * is used for DOCUMENT nodes.
|
---|
327 | *
|
---|
328 | *@@added V0.9.9 (2001-02-14) [umoeller]
|
---|
329 | */
|
---|
330 |
|
---|
331 | typedef struct _DOMDOCUMENTNODE
|
---|
332 | {
|
---|
333 | DOMNODE DomNode;
|
---|
334 |
|
---|
335 | PDOMDOCTYPENODE pDocType;
|
---|
336 | // != NULL if DOCTYPE was found
|
---|
337 |
|
---|
338 | } DOMDOCUMENTNODE, *PDOMDOCUMENTNODE;
|
---|
339 |
|
---|
340 | APIRET xmlCreateDomNode(PDOMNODE pParentNode,
|
---|
341 | NODEBASETYPE ulNodeType,
|
---|
342 | const char *pcszNodeName,
|
---|
343 | ULONG ulNodeNameLength,
|
---|
344 | PDOMNODE *ppNew);
|
---|
345 |
|
---|
346 | VOID xmlDeleteNode(PNODEBASE pNode);
|
---|
347 |
|
---|
348 | /* ******************************************************************
|
---|
349 | *
|
---|
350 | * Specific DOM node constructors
|
---|
351 | *
|
---|
352 | ********************************************************************/
|
---|
353 |
|
---|
354 | APIRET xmlCreateElementNode(PDOMNODE pParent,
|
---|
355 | const char *pcszElement,
|
---|
356 | PDOMNODE *ppNew);
|
---|
357 |
|
---|
358 | APIRET xmlCreateAttributeNode(PDOMNODE pElement,
|
---|
359 | const char *pcszName,
|
---|
360 | const char *pcszValue,
|
---|
361 | PDOMNODE *ppNew);
|
---|
362 |
|
---|
363 | APIRET xmlCreateTextNode(PDOMNODE pParent,
|
---|
364 | const char *pcszText,
|
---|
365 | ULONG ulLength,
|
---|
366 | PDOMNODE *ppNew);
|
---|
367 |
|
---|
368 | APIRET xmlCreateCommentNode(PDOMNODE pParent,
|
---|
369 | const char *pcszText,
|
---|
370 | PDOMNODE *ppNew);
|
---|
371 |
|
---|
372 | APIRET xmlCreatePINode(PDOMNODE pParent,
|
---|
373 | const char *pcszTarget,
|
---|
374 | const char *pcszData,
|
---|
375 | PDOMNODE *ppNew);
|
---|
376 |
|
---|
377 | APIRET xmlCreateDocumentTypeNode(PDOMDOCUMENTNODE pDocumentNode,
|
---|
378 | const char *pcszDoctypeName,
|
---|
379 | const char *pcszSysid,
|
---|
380 | const char *pcszPubid,
|
---|
381 | int fHasInternalSubset,
|
---|
382 | PDOMDOCTYPENODE *ppNew);
|
---|
383 |
|
---|
384 | /* ******************************************************************
|
---|
385 | *
|
---|
386 | * DOM level 3 content models
|
---|
387 | *
|
---|
388 | ********************************************************************/
|
---|
389 |
|
---|
390 | // data types (XML schemes):
|
---|
391 | #define STRING_DATATYPE 1
|
---|
392 | #define BOOLEAN_DATATYPE 2
|
---|
393 | #define FLOAT_DATATYPE 3
|
---|
394 | #define DOUBLE_DATATYPE 4
|
---|
395 | #define LONG_DATATYPE 5
|
---|
396 | #define INT_DATATYPE 6
|
---|
397 | #define SHORT_DATATYPE 7
|
---|
398 | #define BYTE_DATATYPE 8
|
---|
399 |
|
---|
400 | /*
|
---|
401 | *@@ CMELEMENTPARTICLE:
|
---|
402 | * element declaration particle in a
|
---|
403 | * _CMELEMENTDECLNODE.
|
---|
404 | *
|
---|
405 | * One of these structures is a full
|
---|
406 | * (non-pointer) member in _CMELEMENTDECLNODE.
|
---|
407 | * This struct in turn has a linked list with
|
---|
408 | * possible subnodes. See _CMELEMENTDECLNODE.
|
---|
409 | *
|
---|
410 | *@@added V0.9.9 (2001-02-16) [umoeller]
|
---|
411 | */
|
---|
412 |
|
---|
413 | typedef struct _CMELEMENTPARTICLE
|
---|
414 | {
|
---|
415 | NODEBASE NodeBase; // has TREE* as first item in turn
|
---|
416 | // NODEBASE.ulNodeType may be one of these:
|
---|
417 | // -- ELEMENTPARTICLE_EMPTY:
|
---|
418 | // ulRepeater will be XML_CQUANT_NONE, rest is NULL
|
---|
419 | // -- ELEMENTPARTICLE_ANY:
|
---|
420 | // ulRepeater will be XML_CQUANT_NONE, rest is NULL
|
---|
421 | // -- ELEMENTPARTICLE_MIXED:
|
---|
422 | // mixed content (with PCDATA); if the list contains
|
---|
423 | // something, the element may have PCDATA and sub-elements
|
---|
424 | // mixed
|
---|
425 | // -- ELEMENTPARTICLE_CHOICE:
|
---|
426 | // list is a choicelist
|
---|
427 | // -- ELEMENTPARTICLE_SEQ:
|
---|
428 | // list is a seqlist
|
---|
429 | // -- ELEMENTPARTICLE_NAME:
|
---|
430 | // used for terminal particles in a parent particle's
|
---|
431 | // list, which finally specifies the name of a sub-particle.
|
---|
432 | // This can never appear in a root particle.
|
---|
433 |
|
---|
434 | ULONG ulRepeater;
|
---|
435 | // one of:
|
---|
436 | // -- XML_CQUANT_NONE --> all fields below are NULL
|
---|
437 | // -- XML_CQUANT_OPT, question mark
|
---|
438 | // -- XML_CQUANT_REP, asterisk
|
---|
439 | // -- XML_CQUANT_PLUS plus sign
|
---|
440 |
|
---|
441 | struct _CMELEMENTPARTICLE *pParentParticle; // or NULL if this is in the
|
---|
442 | // CMELEMENTDECLNODE
|
---|
443 |
|
---|
444 | PLINKLIST pllSubNodes;
|
---|
445 | // linked list of sub-CMELEMENTPARTICLE structs
|
---|
446 | // (for mixed, choice, seq types);
|
---|
447 | // if NULL, there's no sub-CMELEMENTPARTICLE
|
---|
448 |
|
---|
449 | } CMELEMENTPARTICLE, *PCMELEMENTPARTICLE;
|
---|
450 |
|
---|
451 | /*
|
---|
452 | *@@ CMELEMENTDECLNODE:
|
---|
453 | * representation of an @element_declaration within a
|
---|
454 | * _DOMDOCTYPENODE (a document @DTD).
|
---|
455 | *
|
---|
456 | * This is complicated because element declarations
|
---|
457 | * are complicated with nested lists and content
|
---|
458 | * particles. For this, we introduce the representation
|
---|
459 | * of a _CMELEMENTPARTICLE, which is contained in the
|
---|
460 | * "Particle" member.
|
---|
461 | *
|
---|
462 | * For minimal memory consumption, the _CMELEMENTDECLNODE
|
---|
463 | * is an _CMELEMENTPARTICLE with extra fields, while the
|
---|
464 | * list in _CMELEMENTPARTICLE points to plain
|
---|
465 | * _CMELEMENTPARTICLE structs only.
|
---|
466 | *
|
---|
467 | * For the "root" element declaration in the DTD,
|
---|
468 | * Particle.NODEBASE.ulNodeType will always be one of the following:
|
---|
469 | *
|
---|
470 | * -- ELEMENTPARTICLE_EMPTY: element must be empty.
|
---|
471 | *
|
---|
472 | * -- ELEMENTPARTICLE_ANY: element can have any content.
|
---|
473 | *
|
---|
474 | * -- ELEMENTPARTICLE_CHOICE: _CMELEMENTPARTICLE has a choicelist with
|
---|
475 | * more _CMELEMENTPARTICLE structs.
|
---|
476 | *
|
---|
477 | * -- ELEMENTPARTICLE_SEQ: _CMELEMENTPARTICLE has a seqlist with
|
---|
478 | * more _CMELEMENTPARTICLE structs.
|
---|
479 | *
|
---|
480 | * -- ELEMENTPARTICLE_MIXED: element can have mixed content including #PCDATA.
|
---|
481 | * If there is no content particle list, then the element may
|
---|
482 | * ONLY have PCDATA. If there's a content particle list, then the
|
---|
483 | * element may have both sub-elements and PCDATA. Oh my.
|
---|
484 | *
|
---|
485 | *@@added V0.9.9 (2001-02-14) [umoeller]
|
---|
486 | */
|
---|
487 |
|
---|
488 | typedef struct _CMELEMENTDECLNODE
|
---|
489 | {
|
---|
490 | CMELEMENTPARTICLE Particle;
|
---|
491 | // root particle for this element decl; this may contain
|
---|
492 | // sub-particles...
|
---|
493 | // this has a NODEBASE as first member, which has TREE* as
|
---|
494 | // first item in turn
|
---|
495 |
|
---|
496 | TREE *ParticleNamesTree;
|
---|
497 | // tree sorted by element names with all sub-particles,
|
---|
498 | // no matter how deeply nested; this is just for quickly
|
---|
499 | // checking if an element name is allowed as a sub-element
|
---|
500 | // at all. Tree items are _CMELEMENTPARTICLE nodes.
|
---|
501 |
|
---|
502 | } CMELEMENTDECLNODE, *PCMELEMENTDECLNODE;
|
---|
503 |
|
---|
504 | typedef enum _ATTRIBCONSTRAINT
|
---|
505 | {
|
---|
506 | CMAT_IMPLIED,
|
---|
507 | CMAT_REQUIRED,
|
---|
508 | CMAT_DEFAULT_VALUE,
|
---|
509 | CMAT_FIXED_VALUE
|
---|
510 | } ATTRIBCONSTRAINT;
|
---|
511 |
|
---|
512 | typedef enum _ATTRIBTYPE
|
---|
513 | {
|
---|
514 | CMAT_CDATA,
|
---|
515 | CMAT_ID,
|
---|
516 | CMAT_IDREF,
|
---|
517 | CMAT_IDREFS,
|
---|
518 | CMAT_ENTITY,
|
---|
519 | CMAT_ENTITIES,
|
---|
520 | CMAT_NMTOKEN,
|
---|
521 | CMAT_NMTOKENS,
|
---|
522 | CMAT_ENUM
|
---|
523 | } ATTRIBTYPE;
|
---|
524 |
|
---|
525 | /*
|
---|
526 | *@@ CMATTRIBUTEDECL:
|
---|
527 | * single attribute declaration within the attribute
|
---|
528 | * declarations tree in _CMATTRIBUTEDECLBASE.
|
---|
529 | *
|
---|
530 | *@@added V0.9.9 (2001-02-16) [umoeller]
|
---|
531 | */
|
---|
532 |
|
---|
533 | typedef struct _CMATTRIBUTEDECL
|
---|
534 | {
|
---|
535 | NODEBASE NodeBase; // has TREE* as first item in turn
|
---|
536 | // NodeBase.strName is attribute name
|
---|
537 |
|
---|
538 | ATTRIBTYPE ulAttrType;
|
---|
539 | // one of:
|
---|
540 | // -- CMAT_CDATA
|
---|
541 | // -- CMAT_ID
|
---|
542 | // -- CMAT_IDREF
|
---|
543 | // -- CMAT_IDREFS
|
---|
544 | // -- CMAT_ENTITY
|
---|
545 | // -- CMAT_ENTITIES
|
---|
546 | // -- CMAT_NMTOKEN
|
---|
547 | // -- CMAT_NMTOKENS
|
---|
548 | // -- CMAT_ENUM: pllEnum lists the allowed values.
|
---|
549 | TREE *ValuesTree;
|
---|
550 | // enumeration of allowed values, if CMAT_ENUM;
|
---|
551 | // tree entries are plain NODEBASEs with
|
---|
552 | // ATTRIBUTE_DECLARATION_ENUM type
|
---|
553 |
|
---|
554 | ATTRIBCONSTRAINT ulConstraint;
|
---|
555 | // one of:
|
---|
556 | // -- CMAT_IMPLIED: attrib can have any value.
|
---|
557 | // -- CMAT_REQUIRED: attrib must be specified.
|
---|
558 | // -- CMAT_DEFAULT_VALUE: attrib is optional and has default
|
---|
559 | // value as in pstrDefaultValue.
|
---|
560 | // -- CMAT_FIXED_VALUE: attrib is optional, but must have
|
---|
561 | // fixed value as in pstrDefaultValue.
|
---|
562 | PXSTRING pstrDefaultValue;
|
---|
563 | // default value of this attribute; NULL with implied or required
|
---|
564 |
|
---|
565 | } CMATTRIBUTEDECL, *PCMATTRIBUTEDECL;
|
---|
566 |
|
---|
567 | /*
|
---|
568 | *@@ CMATTRIBUTEDECLBASE:
|
---|
569 | * representation of an @attribute_declaration.
|
---|
570 | *
|
---|
571 | * I'd love to have stored the attribute declarations with
|
---|
572 | * the element specifications, but the XML spec says that
|
---|
573 | * attribute declarations are allowed even if no element
|
---|
574 | * declaration exists for the element to which the attribute
|
---|
575 | * belongs. Now, whatever this is good for... anyway, this
|
---|
576 | * forces us to do a second tree in the _DOMDOCTYPENODE node
|
---|
577 | * according to attribute's element names.
|
---|
578 | *
|
---|
579 | *@@added V0.9.9 (2001-02-14) [umoeller]
|
---|
580 | */
|
---|
581 |
|
---|
582 | typedef struct _CMATTRIBUTEDECLBASE
|
---|
583 | {
|
---|
584 | NODEBASE NodeBase; // has TREE* as first item in turn
|
---|
585 | // NodeBase.strName is element name
|
---|
586 |
|
---|
587 | TREE *AttribDeclsTree;
|
---|
588 | // root of tree with CMATTRIBUTEDECL;
|
---|
589 |
|
---|
590 | } CMATTRIBUTEDECLBASE, *PCMATTRIBUTEDECLBASE;
|
---|
591 |
|
---|
592 | /*
|
---|
593 | *@@ CMENTITYDECLNODE:
|
---|
594 | *
|
---|
595 | * See @entity_declaration.
|
---|
596 | *
|
---|
597 | *@@added V0.9.9 (2001-02-14) [umoeller]
|
---|
598 | */
|
---|
599 |
|
---|
600 | typedef struct _CMENTITYDECLNODE
|
---|
601 | {
|
---|
602 | NODEBASE NodeBase;
|
---|
603 | } CMENTITYDECLNODE, *PCMENTITYDECLNODE;
|
---|
604 |
|
---|
605 | /*
|
---|
606 | *@@ CMNOTATIONDECLNODE:
|
---|
607 | *
|
---|
608 | * See @notation_declaration.
|
---|
609 | *
|
---|
610 | *@@added V0.9.9 (2001-02-14) [umoeller]
|
---|
611 | */
|
---|
612 |
|
---|
613 | typedef struct _CMNOTATIONDECLNODE
|
---|
614 | {
|
---|
615 | NODEBASE NodeBase;
|
---|
616 | } CMNOTATIONDECLNODE, *PCMNOTATIONDECLNODE;
|
---|
617 |
|
---|
618 | APIRET xmlCreateElementDecl(const char *pcszName,
|
---|
619 | PXMLCONTENT pModel,
|
---|
620 | PCMELEMENTDECLNODE *ppNew);
|
---|
621 |
|
---|
622 | /* ******************************************************************
|
---|
623 | *
|
---|
624 | * DOM parser APIs
|
---|
625 | *
|
---|
626 | ********************************************************************/
|
---|
627 |
|
---|
628 | typedef struct _XMLDOM *PXMLDOM;
|
---|
629 |
|
---|
630 | typedef int APIENTRY FNGETCPDATA(PXMLDOM pDom, ULONG ulCP, int *piMap);
|
---|
631 | typedef FNGETCPDATA *PFNGETCPDATA;
|
---|
632 |
|
---|
633 | typedef APIRET APIENTRY FNEXTERNALHANDLER(PXMLDOM pDom,
|
---|
634 | XML_Parser pSubParser,
|
---|
635 | const char *pcszSystemID,
|
---|
636 | const char *pcszPublicID);
|
---|
637 | typedef FNEXTERNALHANDLER *PFNEXTERNALHANDLER;
|
---|
638 |
|
---|
639 | /*
|
---|
640 | *@@ STATICSYSTEMID:
|
---|
641 | * specification of a supported static system
|
---|
642 | * ID, which is most helpful with predefined
|
---|
643 | * DTD's.
|
---|
644 | *
|
---|
645 | * An array of this structure can be passed to
|
---|
646 | * xmlCreateDOM to avoid having to supply an
|
---|
647 | * external entity reference callback.
|
---|
648 | *
|
---|
649 | * This has one system ID with a corresponding
|
---|
650 | * contents (normally a DTD) so the
|
---|
651 | * implementation's external entity handler can
|
---|
652 | * parse the doctype automatically.
|
---|
653 | *
|
---|
654 | *@@added V0.9.20 (2002-07-06) [umoeller]
|
---|
655 | */
|
---|
656 |
|
---|
657 | typedef struct _STATICSYSTEMID
|
---|
658 | {
|
---|
659 | PCSZ pcszSystemId;
|
---|
660 | // possible system ID specified in DTD, e.g. "warpin.dtd"
|
---|
661 | // (without quotes)
|
---|
662 |
|
---|
663 | PCSZ pcszContent;
|
---|
664 | // corresponding external DTD subset without square brackets,
|
---|
665 | // e.g. "<!ELEMENT job EMPTY >\n"
|
---|
666 | // (without quotes)
|
---|
667 |
|
---|
668 | } STATICSYSTEMID, *PSTATICSYSTEMID;
|
---|
669 |
|
---|
670 | /*
|
---|
671 | *@@ XMLDOM:
|
---|
672 | * DOM instance returned by xmlCreateDOM.
|
---|
673 | *
|
---|
674 | *@@added V0.9.9 (2001-02-14) [umoeller]
|
---|
675 | */
|
---|
676 |
|
---|
677 | typedef struct _XMLDOM
|
---|
678 | {
|
---|
679 | /*
|
---|
680 | * Public fields (should be read only)
|
---|
681 | */
|
---|
682 |
|
---|
683 | PDOMDOCUMENTNODE pDocumentNode;
|
---|
684 | // document node (contains all the elements)
|
---|
685 |
|
---|
686 | PDOMDOCTYPENODE pDocTypeNode;
|
---|
687 | // != NULL only if the document has a DOCTYPE
|
---|
688 |
|
---|
689 | // error handling
|
---|
690 | APIRET arcDOM; // validation errors etc.;
|
---|
691 | // if != 0, this has a detailed
|
---|
692 | // expat or DOM error code
|
---|
693 | BOOL fInvalid; // TRUE if validation failed
|
---|
694 | // (parser error otherwise)
|
---|
695 |
|
---|
696 | const char *pcszErrorDescription; // error description
|
---|
697 | PXSTRING pxstrSystemID; // system ID of external entity
|
---|
698 | // where error occured, or NULL
|
---|
699 | // if in main document
|
---|
700 | ULONG ulErrorLine; // line where error occured
|
---|
701 | ULONG ulErrorColumn; // column where error occured
|
---|
702 | PXSTRING pxstrFailingNode; // element or attribute name
|
---|
703 | // or NULL
|
---|
704 |
|
---|
705 | /*
|
---|
706 | * Private fields (for xml* functions)
|
---|
707 | */
|
---|
708 |
|
---|
709 | // params copied from xmlCreateDOM
|
---|
710 | ULONG flParserFlags;
|
---|
711 | PFNGETCPDATA pfnGetCPData;
|
---|
712 | PFNEXTERNALHANDLER pfnExternalHandler;
|
---|
713 | PVOID pvCallbackUser;
|
---|
714 | const STATICSYSTEMID *paSystemIds;
|
---|
715 | ULONG cSystemIds;
|
---|
716 |
|
---|
717 | XML_Parser pParser;
|
---|
718 | // expat parser instance
|
---|
719 |
|
---|
720 | LINKLIST llElementStack;
|
---|
721 | // stack for maintaining the current items;
|
---|
722 | // these point to DOMSTACKITEMs (auto-free)
|
---|
723 |
|
---|
724 | PDOMNODE pLastWasTextNode;
|
---|
725 |
|
---|
726 | PCMATTRIBUTEDECLBASE pAttListDeclCache;
|
---|
727 | // cache for attribute declarations according
|
---|
728 | // to attdecl element name
|
---|
729 | } XMLDOM;
|
---|
730 |
|
---|
731 | #define DF_PARSECOMMENTS 0x0001
|
---|
732 | #define DF_PARSEDTD 0x0002
|
---|
733 | #define DF_FAIL_IF_NO_DTD 0x0004
|
---|
734 | #define DF_DROP_WHITESPACE 0x0008
|
---|
735 |
|
---|
736 | APIRET xmlCreateDOM(ULONG flParserFlags,
|
---|
737 | const STATICSYSTEMID *paSystemIds,
|
---|
738 | ULONG cSystemIds,
|
---|
739 | PFNGETCPDATA pfnGetCPData,
|
---|
740 | PFNEXTERNALHANDLER pfnExternalHandler,
|
---|
741 | PVOID pvCallbackUser,
|
---|
742 | PXMLDOM *ppDom);
|
---|
743 |
|
---|
744 | APIRET xmlParse(PXMLDOM pDom,
|
---|
745 | const char *pcszBuf,
|
---|
746 | ULONG cb,
|
---|
747 | BOOL fIsLast);
|
---|
748 |
|
---|
749 | VOID xmlDump(PXMLDOM pDom);
|
---|
750 |
|
---|
751 | APIRET xmlFreeDOM(PXMLDOM pDom);
|
---|
752 |
|
---|
753 | /* ******************************************************************
|
---|
754 | *
|
---|
755 | * DOM lookup
|
---|
756 | *
|
---|
757 | ********************************************************************/
|
---|
758 |
|
---|
759 | PCMELEMENTDECLNODE xmlFindElementDecl(PXMLDOM pDom,
|
---|
760 | const XSTRING *pcszElementName);
|
---|
761 |
|
---|
762 | PCMATTRIBUTEDECLBASE xmlFindAttribDeclBase(PXMLDOM pDom,
|
---|
763 | const XSTRING *pstrElementName);
|
---|
764 |
|
---|
765 | PCMATTRIBUTEDECL xmlFindAttribDecl(PXMLDOM pDom,
|
---|
766 | const XSTRING *pstrElementName,
|
---|
767 | const XSTRING *pstrAttribName,
|
---|
768 | PCMATTRIBUTEDECLBASE *ppAttribDeclBase);
|
---|
769 |
|
---|
770 | PDOMNODE xmlGetRootElement(PXMLDOM pDom);
|
---|
771 |
|
---|
772 | PDOMNODE xmlGetFirstChild(PDOMNODE pDomNode);
|
---|
773 |
|
---|
774 | PDOMNODE xmlGetLastChild(PDOMNODE pDomNode);
|
---|
775 |
|
---|
776 | PDOMNODE xmlGetFirstText(PDOMNODE pElement);
|
---|
777 |
|
---|
778 | PLINKLIST xmlGetElementsByTagName(PDOMNODE pParent,
|
---|
779 | const char *pcszName);
|
---|
780 |
|
---|
781 | const XSTRING* xmlGetAttribute(PDOMNODE pElement,
|
---|
782 | const char *pcszAttribName);
|
---|
783 |
|
---|
784 | /* ******************************************************************
|
---|
785 | *
|
---|
786 | * DOM build
|
---|
787 | *
|
---|
788 | ********************************************************************/
|
---|
789 |
|
---|
790 | APIRET xmlCreateDocument(const char *pcszRootElementName,
|
---|
791 | PDOMDOCUMENTNODE *ppDocument,
|
---|
792 | PDOMNODE *ppRootElement);
|
---|
793 |
|
---|
794 | APIRET xmlWriteDocument(PDOMDOCUMENTNODE pDocument,
|
---|
795 | const char *pcszEncoding,
|
---|
796 | const char *pcszDoctype,
|
---|
797 | PXSTRING pxstr);
|
---|
798 | #endif
|
---|
799 |
|
---|
800 | #if __cplusplus
|
---|
801 | }
|
---|
802 | #endif
|
---|
803 |
|
---|