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 | // @@@todo these
|
---|
88 | #define ERROR_DOM_VALIDATE_INVALID_ELEMENT (ERROR_XML_FIRST + 44)
|
---|
89 | #define ERROR_DOM_ELEMENT_DECL_OUTSIDE_DOCTYPE (ERROR_XML_FIRST + 45)
|
---|
90 | #define ERROR_DOM_ATTLIST_DECL_OUTSIDE_DOCTYPE (ERROR_XML_FIRST + 46)
|
---|
91 |
|
---|
92 | const char* xmlDescribeError(int code);
|
---|
93 |
|
---|
94 | /* ******************************************************************
|
---|
95 | *
|
---|
96 | * Most basic node management
|
---|
97 | *
|
---|
98 | ********************************************************************/
|
---|
99 |
|
---|
100 | // content model node types:
|
---|
101 | typedef enum _NODEBASETYPE
|
---|
102 | {
|
---|
103 | TYPE_UNKNOWN,
|
---|
104 |
|
---|
105 | DOMNODE_ELEMENT, // node is a DOM ELEMENT
|
---|
106 | DOMNODE_ATTRIBUTE, // node is a DOM ATTRIBUTE
|
---|
107 | DOMNODE_TEXT, // node is a DOM TEXT node
|
---|
108 | // DOMNODE_CDATA_SECTION 4
|
---|
109 | // DOMNODE_ENTITY_REFERENCE 5
|
---|
110 | // DOMNODE_ENTITY 6
|
---|
111 | DOMNODE_PROCESSING_INSTRUCTION, // node is a DOM PI
|
---|
112 | DOMNODE_COMMENT, // node is a DOM COMMENT
|
---|
113 | DOMNODE_DOCUMENT, // node is a DOM document
|
---|
114 | DOMNODE_DOCUMENT_TYPE, // node is a DOM DOCUMENTTYPE
|
---|
115 | // #define DOMNODE_DOCUMENT_FRAGMENT 11
|
---|
116 | // #define DOMNODE_NOTATION 12
|
---|
117 |
|
---|
118 | // the following are all CMELEMENTPARTICLE nodes
|
---|
119 | ELEMENTPARTICLE_EMPTY,
|
---|
120 | ELEMENTPARTICLE_ANY,
|
---|
121 | ELEMENTPARTICLE_MIXED,
|
---|
122 | ELEMENTPARTICLE_CHOICE,
|
---|
123 | ELEMENTPARTICLE_SEQ,
|
---|
124 | ELEMENTPARTICLE_NAME,
|
---|
125 |
|
---|
126 | ATTRIBUTE_DECLARATION_BASE, // node is a CMATTRIBUTEDECLBASE
|
---|
127 | ATTRIBUTE_DECLARATION, // node is a CMATTRIBUTEDECL
|
---|
128 | ATTRIBUTE_DECLARATION_ENUM // node is a plain NODEBASE, part of an attr value enum
|
---|
129 | } NODEBASETYPE;
|
---|
130 |
|
---|
131 | /*
|
---|
132 | *@@ NODEBASE:
|
---|
133 | * root class of all nodes used in the
|
---|
134 | * DOM tree.
|
---|
135 | *
|
---|
136 | * The first item is a TREE to make this insertable
|
---|
137 | * into string maps via the functions in tree.c.
|
---|
138 | *
|
---|
139 | * A NODEBASE is also the first member of a DOMNODE
|
---|
140 | * so this is effectively a simulation of inheritance
|
---|
141 | * in plain C... DOMNODE inherits from NODEBASE,
|
---|
142 | * and some other types inherit from DOMNODE.
|
---|
143 | *
|
---|
144 | * This contains the node name, which is also used
|
---|
145 | * by the DOMNODE's (e.g. for element names).
|
---|
146 | * However, only DOMNODE defines the node value
|
---|
147 | * string.
|
---|
148 | *
|
---|
149 | *@@added V0.9.9 (2001-02-14) [umoeller]
|
---|
150 | */
|
---|
151 |
|
---|
152 | typedef struct _NODEBASE
|
---|
153 | {
|
---|
154 | TREE Tree; // tree.c
|
---|
155 |
|
---|
156 | NODEBASETYPE ulNodeType; // class type; this is precious,
|
---|
157 | // all xml* functions make assumptions
|
---|
158 | // from this value
|
---|
159 |
|
---|
160 | XSTRING strNodeName;
|
---|
161 | // node name;
|
---|
162 | // -- for the various DOMNODE_* items, see _DOMNODE;
|
---|
163 | // -- for CMELEMENTPARTICLE nodes, this is the particle's name
|
---|
164 | // -- for CMELEMENTDECLNODE nodes, element name being declared
|
---|
165 | // -- for CMATTRIBUTEDECLBASE nodes, name of element to which this
|
---|
166 | // attrib decl belongs
|
---|
167 | // -- for CMATTRIBUTEDECL nodes, name of attribute;
|
---|
168 | // -- for ATTRIBUTE_DECLARATION_ENUM, attribute value in the
|
---|
169 | // possible values list.
|
---|
170 |
|
---|
171 | } NODEBASE, *PNODEBASE;
|
---|
172 |
|
---|
173 | /* ******************************************************************
|
---|
174 | *
|
---|
175 | * DOM level 1
|
---|
176 | *
|
---|
177 | ********************************************************************/
|
---|
178 |
|
---|
179 | /*
|
---|
180 | *@@ DOMNODE:
|
---|
181 | * this represents one @DOM node in an @XML document.
|
---|
182 | *
|
---|
183 | * The document itself is represented by a node with the
|
---|
184 | * DOMNODE_DOCUMENT type, which is the root of a tree as
|
---|
185 | * shown with xmlParse.
|
---|
186 | *
|
---|
187 | * The contents of the members vary according
|
---|
188 | * to ulNodeType (0 specifies that the field does not
|
---|
189 | * apply to that type).
|
---|
190 | *
|
---|
191 | * The first member of a DOMNODE is a NODEBASE to allow
|
---|
192 | * inserting these things in a tree. NODEBASE.ulNodeType
|
---|
193 | * _always_ specifies the various types that are using
|
---|
194 | * that structure to allow for type-safety (if we watch out).
|
---|
195 | * This is for faking inheritance.
|
---|
196 | *
|
---|
197 | * Note that we also implement specialized sub-structures of
|
---|
198 | * DOMNODE, whose first member is the DOMNODE (and therefore
|
---|
199 | * a NODEBASE as well):
|
---|
200 | *
|
---|
201 | * -- DOCUMENT nodes are given a _DOMDOCUMENTNODE structure.
|
---|
202 | *
|
---|
203 | * -- DOCTYPE nodes are given a _DOMDOCTYPENODE structure.
|
---|
204 | *
|
---|
205 | * Overview of member fields usage:
|
---|
206 | +
|
---|
207 | + ulNodeType | strNodeName | strNodeValue | llChildren | AttributesMap
|
---|
208 | + (NODEBASE) | (NODEBASE) | (DOMNODE) | (DOMNODE) | (DOMNODE)
|
---|
209 | + =======================================================================
|
---|
210 | + | | | |
|
---|
211 | + DOCUMENT | name from | 0 | 1 root | 0
|
---|
212 | + | DOCTYPE or | | ELEMENT |
|
---|
213 | + | NULL | | |
|
---|
214 | + | | | |
|
---|
215 | + --------------+-------------+--------------+------------+--------------
|
---|
216 | + | | | |
|
---|
217 | + ELEMENT | tag name | 0 | ELEMENT | ATTRIBUTE
|
---|
218 | + | | | nodes | nodes
|
---|
219 | + | | | |
|
---|
220 | + --------------+-------------+--------------+------------+--------------
|
---|
221 | + | | | |
|
---|
222 | + ATTRIBUTE | attribute | attribute | 0 | 0
|
---|
223 | + | name | value | |
|
---|
224 | + | | | |
|
---|
225 | + --------------+-------------+--------------+------------+--------------
|
---|
226 | + | | | |
|
---|
227 | + TEXT | 0 | text | 0 | 0
|
---|
228 | + | | contents | |
|
---|
229 | + | | | |
|
---|
230 | + --------------+-------------+--------------+------------+--------------
|
---|
231 | + | | | |
|
---|
232 | + COMMENT | 0 | comment | 0 | 0
|
---|
233 | + | | contents | |
|
---|
234 | + | | | |
|
---|
235 | + --------------+-------------+--------------+------------+--------------
|
---|
236 | + | | | |
|
---|
237 | + PI | PI target | PI data | 0 | 0
|
---|
238 | + | | | |
|
---|
239 | + | | | |
|
---|
240 | + --------------+-------------+--------------+------------+--------------
|
---|
241 | + | | | |
|
---|
242 | + DOCTYPE | doctype | | 0 | 0
|
---|
243 | + | name | | |
|
---|
244 | + | | | |
|
---|
245 | +
|
---|
246 | * The xwphelpers implementation does not implement CDATA sections,
|
---|
247 | * for which we have no need because @expat properly converts these
|
---|
248 | * into plain @content.
|
---|
249 | *
|
---|
250 | * In addition, W3C DOM specifies that the "node name" members contain
|
---|
251 | * "#document", "#text", and "#comment" strings for DOCUMENT,
|
---|
252 | * TEXT, and COMMENT nodes, respectively. I see no point in this other
|
---|
253 | * than consuming memory, so these fields are empty with this implementation.
|
---|
254 | */
|
---|
255 |
|
---|
256 | typedef struct _DOMNODE
|
---|
257 | {
|
---|
258 | NODEBASE NodeBase;
|
---|
259 |
|
---|
260 | PXSTRING pstrNodeValue; // ptr is NULL if none
|
---|
261 |
|
---|
262 | struct _DOMNODE *pParentNode;
|
---|
263 | // the parent node;
|
---|
264 | // NULL for DOCUMENT, DOCUMENT_FRAGMENT.
|
---|
265 | // The DOM spec says that attribs have no parent,
|
---|
266 | // but even though the attribute is not added to
|
---|
267 | // the "children" list of an element (but to the
|
---|
268 | // attributes map instead), we specify the element
|
---|
269 | // as the attribute's parent here.
|
---|
270 |
|
---|
271 | struct _DOMNODE *pDocumentNode;
|
---|
272 | // the document node, unless this is a DOCUMENT in itself.
|
---|
273 |
|
---|
274 | LINKLIST llChildren; // of DOMNODE* pointers, no auto-free
|
---|
275 |
|
---|
276 | TREE *AttributesMap; // of DOMNODE* pointers
|
---|
277 |
|
---|
278 | } DOMNODE, *PDOMNODE;
|
---|
279 |
|
---|
280 | /*
|
---|
281 | *@@ DOMDOCTYPENODE:
|
---|
282 | * specific _DOMNODE replacement structure which
|
---|
283 | * is used for DOCTYPE nodes.
|
---|
284 | *
|
---|
285 | * The DOMDOCTYPENODE is special (other than having
|
---|
286 | * extra fields) in that it is stored both in
|
---|
287 | * the document node's children list and in its
|
---|
288 | * pDocType field.
|
---|
289 | *
|
---|
290 | * DOMNODE.pstrNodeName is set to the name in the
|
---|
291 | * DOCTYPE statement by xmlCreateDocumentTypeNode,
|
---|
292 | * or is NULL if there's no DOCTYPE.
|
---|
293 | *
|
---|
294 | *@@added V0.9.9 (2001-02-14) [umoeller]
|
---|
295 | */
|
---|
296 |
|
---|
297 | typedef struct _DOMDOCTYPENODE
|
---|
298 | {
|
---|
299 | DOMNODE DomNode;
|
---|
300 |
|
---|
301 | XSTRING strPublicID;
|
---|
302 | XSTRING strSystemID;
|
---|
303 |
|
---|
304 | BOOL fHasInternalSubset;
|
---|
305 |
|
---|
306 | TREE *ElementDeclsTree;
|
---|
307 | // tree with pointers to _CMELEMENTDECLNODE nodes
|
---|
308 |
|
---|
309 | TREE *AttribDeclBasesTree;
|
---|
310 | // tree with pointers to _CMATTRIBUTEDECLBASE nodes
|
---|
311 |
|
---|
312 | } DOMDOCTYPENODE, *PDOMDOCTYPENODE;
|
---|
313 |
|
---|
314 | /*
|
---|
315 | *@@ DOMDOCUMENTNODE:
|
---|
316 | * specific _DOMNODE replacement structure which
|
---|
317 | * is used for DOCUMENT nodes.
|
---|
318 | *
|
---|
319 | *@@added V0.9.9 (2001-02-14) [umoeller]
|
---|
320 | */
|
---|
321 |
|
---|
322 | typedef struct _DOMDOCUMENTNODE
|
---|
323 | {
|
---|
324 | DOMNODE DomNode;
|
---|
325 |
|
---|
326 | PDOMDOCTYPENODE pDocType;
|
---|
327 | // != NULL if DOCTYPE was found
|
---|
328 |
|
---|
329 | } DOMDOCUMENTNODE, *PDOMDOCUMENTNODE;
|
---|
330 |
|
---|
331 | APIRET xmlCreateDomNode(PDOMNODE pParentNode,
|
---|
332 | NODEBASETYPE ulNodeType,
|
---|
333 | const char *pcszNodeName,
|
---|
334 | ULONG ulNodeNameLength,
|
---|
335 | PDOMNODE *ppNew);
|
---|
336 |
|
---|
337 | VOID xmlDeleteNode(PNODEBASE pNode);
|
---|
338 |
|
---|
339 | /* ******************************************************************
|
---|
340 | *
|
---|
341 | * Specific DOM node constructors
|
---|
342 | *
|
---|
343 | ********************************************************************/
|
---|
344 |
|
---|
345 | APIRET xmlCreateElementNode(PDOMNODE pParent,
|
---|
346 | const char *pcszElement,
|
---|
347 | PDOMNODE *ppNew);
|
---|
348 |
|
---|
349 | APIRET xmlCreateAttributeNode(PDOMNODE pElement,
|
---|
350 | const char *pcszName,
|
---|
351 | const char *pcszValue,
|
---|
352 | PDOMNODE *ppNew);
|
---|
353 |
|
---|
354 | APIRET xmlCreateTextNode(PDOMNODE pParent,
|
---|
355 | const char *pcszText,
|
---|
356 | ULONG ulLength,
|
---|
357 | PDOMNODE *ppNew);
|
---|
358 |
|
---|
359 | APIRET xmlCreateCommentNode(PDOMNODE pParent,
|
---|
360 | const char *pcszText,
|
---|
361 | PDOMNODE *ppNew);
|
---|
362 |
|
---|
363 | APIRET xmlCreatePINode(PDOMNODE pParent,
|
---|
364 | const char *pcszTarget,
|
---|
365 | const char *pcszData,
|
---|
366 | PDOMNODE *ppNew);
|
---|
367 |
|
---|
368 | APIRET xmlCreateDocumentTypeNode(PDOMDOCUMENTNODE pDocumentNode,
|
---|
369 | const char *pcszDoctypeName,
|
---|
370 | const char *pcszSysid,
|
---|
371 | const char *pcszPubid,
|
---|
372 | int fHasInternalSubset,
|
---|
373 | PDOMDOCTYPENODE *ppNew);
|
---|
374 |
|
---|
375 | /* ******************************************************************
|
---|
376 | *
|
---|
377 | * DOM level 3 content models
|
---|
378 | *
|
---|
379 | ********************************************************************/
|
---|
380 |
|
---|
381 | // data types (XML schemes):
|
---|
382 | #define STRING_DATATYPE 1
|
---|
383 | #define BOOLEAN_DATATYPE 2
|
---|
384 | #define FLOAT_DATATYPE 3
|
---|
385 | #define DOUBLE_DATATYPE 4
|
---|
386 | #define LONG_DATATYPE 5
|
---|
387 | #define INT_DATATYPE 6
|
---|
388 | #define SHORT_DATATYPE 7
|
---|
389 | #define BYTE_DATATYPE 8
|
---|
390 |
|
---|
391 | /*
|
---|
392 | *@@ CMELEMENTPARTICLE:
|
---|
393 | * element declaration particle in a
|
---|
394 | * _CMELEMENTDECLNODE.
|
---|
395 | *
|
---|
396 | * One of these structures is a full
|
---|
397 | * (non-pointer) member in _CMELEMENTDECLNODE.
|
---|
398 | * This struct in turn has a linked list with
|
---|
399 | * possible subnodes. See _CMELEMENTDECLNODE.
|
---|
400 | *
|
---|
401 | *@@added V0.9.9 (2001-02-16) [umoeller]
|
---|
402 | */
|
---|
403 |
|
---|
404 | typedef struct _CMELEMENTPARTICLE
|
---|
405 | {
|
---|
406 | NODEBASE NodeBase; // has TREE* as first item in turn
|
---|
407 | // NODEBASE.ulNodeType may be one of these:
|
---|
408 | // -- ELEMENTPARTICLE_EMPTY:
|
---|
409 | // ulRepeater will be XML_CQUANT_NONE, rest is NULL
|
---|
410 | // -- ELEMENTPARTICLE_ANY:
|
---|
411 | // ulRepeater will be XML_CQUANT_NONE, rest is NULL
|
---|
412 | // -- ELEMENTPARTICLE_MIXED:
|
---|
413 | // mixed content (with PCDATA); if the list contains
|
---|
414 | // something, the element may have PCDATA and sub-elements
|
---|
415 | // mixed
|
---|
416 | // -- ELEMENTPARTICLE_CHOICE:
|
---|
417 | // list is a choicelist
|
---|
418 | // -- ELEMENTPARTICLE_SEQ:
|
---|
419 | // list is a seqlist
|
---|
420 | // -- ELEMENTPARTICLE_NAME:
|
---|
421 | // used for terminal particles in a parent particle's
|
---|
422 | // list, which finally specifies the name of a sub-particle.
|
---|
423 | // This can never appear in a root particle.
|
---|
424 |
|
---|
425 | ULONG ulRepeater;
|
---|
426 | // one of:
|
---|
427 | // -- XML_CQUANT_NONE --> all fields below are NULL
|
---|
428 | // -- XML_CQUANT_OPT, question mark
|
---|
429 | // -- XML_CQUANT_REP, asterisk
|
---|
430 | // -- XML_CQUANT_PLUS plus sign
|
---|
431 |
|
---|
432 | struct _CMELEMENTPARTICLE *pParentParticle; // or NULL if this is in the
|
---|
433 | // CMELEMENTDECLNODE
|
---|
434 |
|
---|
435 | PLINKLIST pllSubNodes;
|
---|
436 | // linked list of sub-CMELEMENTPARTICLE structs
|
---|
437 | // (for mixed, choice, seq types);
|
---|
438 | // if NULL, there's no sub-CMELEMENTPARTICLE
|
---|
439 |
|
---|
440 | } CMELEMENTPARTICLE, *PCMELEMENTPARTICLE;
|
---|
441 |
|
---|
442 | /*
|
---|
443 | *@@ CMELEMENTDECLNODE:
|
---|
444 | * representation of an @element_declaration within a
|
---|
445 | * _DOMDOCTYPENODE (a document @DTD).
|
---|
446 | *
|
---|
447 | * This is complicated because element declarations
|
---|
448 | * are complicated with nested lists and content
|
---|
449 | * particles. For this, we introduce the representation
|
---|
450 | * of a _CMELEMENTPARTICLE, which is contained in the
|
---|
451 | * "Particle" member.
|
---|
452 | *
|
---|
453 | * For minimal memory consumption, the _CMELEMENTDECLNODE
|
---|
454 | * is an _CMELEMENTPARTICLE with extra fields, while the
|
---|
455 | * list in _CMELEMENTPARTICLE points to plain
|
---|
456 | * _CMELEMENTPARTICLE structs only.
|
---|
457 | *
|
---|
458 | * For the "root" element declaration in the DTD,
|
---|
459 | * Particle.NODEBASE.ulNodeType will always be one of the following:
|
---|
460 | *
|
---|
461 | * -- ELEMENTPARTICLE_EMPTY: element must be empty.
|
---|
462 | *
|
---|
463 | * -- ELEMENTPARTICLE_ANY: element can have any content.
|
---|
464 | *
|
---|
465 | * -- ELEMENTPARTICLE_CHOICE: _CMELEMENTPARTICLE has a choicelist with
|
---|
466 | * more _CMELEMENTPARTICLE structs.
|
---|
467 | *
|
---|
468 | * -- ELEMENTPARTICLE_SEQ: _CMELEMENTPARTICLE has a seqlist with
|
---|
469 | * more _CMELEMENTPARTICLE structs.
|
---|
470 | *
|
---|
471 | * -- ELEMENTPARTICLE_MIXED: element can have mixed content including #PCDATA.
|
---|
472 | * If there is no content particle list, then the element may
|
---|
473 | * ONLY have PCDATA. If there's a content particle list, then the
|
---|
474 | * element may have both sub-elements and PCDATA. Oh my.
|
---|
475 | *
|
---|
476 | *@@added V0.9.9 (2001-02-14) [umoeller]
|
---|
477 | */
|
---|
478 |
|
---|
479 | typedef struct _CMELEMENTDECLNODE
|
---|
480 | {
|
---|
481 | CMELEMENTPARTICLE Particle;
|
---|
482 | // root particle for this element decl; this may contain
|
---|
483 | // sub-particles...
|
---|
484 | // this has a NODEBASE as first member, which has TREE* as
|
---|
485 | // first item in turn
|
---|
486 |
|
---|
487 | TREE *ParticleNamesTree;
|
---|
488 | // tree sorted by element names with all sub-particles,
|
---|
489 | // no matter how deeply nested; this is just for quickly
|
---|
490 | // checking if an element name is allowed as a sub-element
|
---|
491 | // at all. Tree items are _CMELEMENTPARTICLE nodes.
|
---|
492 |
|
---|
493 | } CMELEMENTDECLNODE, *PCMELEMENTDECLNODE;
|
---|
494 |
|
---|
495 | typedef enum _ATTRIBCONSTRAINT
|
---|
496 | {
|
---|
497 | CMAT_IMPLIED,
|
---|
498 | CMAT_REQUIRED,
|
---|
499 | CMAT_DEFAULT_VALUE,
|
---|
500 | CMAT_FIXED_VALUE
|
---|
501 | } ATTRIBCONSTRAINT;
|
---|
502 |
|
---|
503 | typedef enum _ATTRIBTYPE
|
---|
504 | {
|
---|
505 | CMAT_CDATA,
|
---|
506 | CMAT_ID,
|
---|
507 | CMAT_IDREF,
|
---|
508 | CMAT_IDREFS,
|
---|
509 | CMAT_ENTITY,
|
---|
510 | CMAT_ENTITIES,
|
---|
511 | CMAT_NMTOKEN,
|
---|
512 | CMAT_NMTOKENS,
|
---|
513 | CMAT_ENUM
|
---|
514 | } ATTRIBTYPE;
|
---|
515 |
|
---|
516 | /*
|
---|
517 | *@@ CMATTRIBUTEDECL:
|
---|
518 | * single attribute declaration within the attribute
|
---|
519 | * declarations tree in _CMATTRIBUTEDECLBASE.
|
---|
520 | *
|
---|
521 | *@@added V0.9.9 (2001-02-16) [umoeller]
|
---|
522 | */
|
---|
523 |
|
---|
524 | typedef struct _CMATTRIBUTEDECL
|
---|
525 | {
|
---|
526 | NODEBASE NodeBase; // has TREE* as first item in turn
|
---|
527 | // NodeBase.strName is attribute name
|
---|
528 |
|
---|
529 | ATTRIBTYPE ulAttrType;
|
---|
530 | // one of:
|
---|
531 | // -- CMAT_CDATA
|
---|
532 | // -- CMAT_ID
|
---|
533 | // -- CMAT_IDREF
|
---|
534 | // -- CMAT_IDREFS
|
---|
535 | // -- CMAT_ENTITY
|
---|
536 | // -- CMAT_ENTITIES
|
---|
537 | // -- CMAT_NMTOKEN
|
---|
538 | // -- CMAT_NMTOKENS
|
---|
539 | // -- CMAT_ENUM: pllEnum lists the allowed values.
|
---|
540 | TREE *ValuesTree;
|
---|
541 | // enumeration of allowed values, if CMAT_ENUM;
|
---|
542 | // tree entries are plain NODEBASEs with
|
---|
543 | // ATTRIBUTE_DECLARATION_ENUM type
|
---|
544 |
|
---|
545 | ATTRIBCONSTRAINT ulConstraint;
|
---|
546 | // one of:
|
---|
547 | // -- CMAT_IMPLIED: attrib can have any value.
|
---|
548 | // -- CMAT_REQUIRED: attrib must be specified.
|
---|
549 | // -- CMAT_DEFAULT_VALUE: attrib is optional and has default
|
---|
550 | // value as in pstrDefaultValue.
|
---|
551 | // -- CMAT_FIXED_VALUE: attrib is optional, but must have
|
---|
552 | // fixed value as in pstrDefaultValue.
|
---|
553 | PXSTRING pstrDefaultValue;
|
---|
554 | // default value of this attribute; NULL with implied or required
|
---|
555 |
|
---|
556 | } CMATTRIBUTEDECL, *PCMATTRIBUTEDECL;
|
---|
557 |
|
---|
558 | /*
|
---|
559 | *@@ CMATTRIBUTEDECLBASE:
|
---|
560 | * representation of an @attribute_declaration.
|
---|
561 | *
|
---|
562 | * I'd love to have stored the attribute declarations with
|
---|
563 | * the element specifications, but the XML spec says that
|
---|
564 | * attribute declarations are allowed even if no element
|
---|
565 | * declaration exists for the element to which the attribute
|
---|
566 | * belongs. Now, whatever this is good for... anyway, this
|
---|
567 | * forces us to do a second tree in the _DOMDOCTYPENODE node
|
---|
568 | * according to attribute's element names.
|
---|
569 | *
|
---|
570 | *@@added V0.9.9 (2001-02-14) [umoeller]
|
---|
571 | */
|
---|
572 |
|
---|
573 | typedef struct _CMATTRIBUTEDECLBASE
|
---|
574 | {
|
---|
575 | NODEBASE NodeBase; // has TREE* as first item in turn
|
---|
576 | // NodeBase.strName is element name
|
---|
577 |
|
---|
578 | TREE *AttribDeclsTree;
|
---|
579 | // root of tree with CMATTRIBUTEDECL;
|
---|
580 |
|
---|
581 | } CMATTRIBUTEDECLBASE, *PCMATTRIBUTEDECLBASE;
|
---|
582 |
|
---|
583 | /*
|
---|
584 | *@@ CMENTITYDECLNODE:
|
---|
585 | *
|
---|
586 | * See @entity_declaration.
|
---|
587 | *
|
---|
588 | *@@added V0.9.9 (2001-02-14) [umoeller]
|
---|
589 | */
|
---|
590 |
|
---|
591 | typedef struct _CMENTITYDECLNODE
|
---|
592 | {
|
---|
593 | NODEBASE NodeBase;
|
---|
594 | } CMENTITYDECLNODE, *PCMENTITYDECLNODE;
|
---|
595 |
|
---|
596 | /*
|
---|
597 | *@@ CMNOTATIONDECLNODE:
|
---|
598 | *
|
---|
599 | * See @notation_declaration.
|
---|
600 | *
|
---|
601 | *@@added V0.9.9 (2001-02-14) [umoeller]
|
---|
602 | */
|
---|
603 |
|
---|
604 | typedef struct _CMNOTATIONDECLNODE
|
---|
605 | {
|
---|
606 | NODEBASE NodeBase;
|
---|
607 | } CMNOTATIONDECLNODE, *PCMNOTATIONDECLNODE;
|
---|
608 |
|
---|
609 | APIRET xmlCreateElementDecl(const char *pcszName,
|
---|
610 | PXMLCONTENT pModel,
|
---|
611 | PCMELEMENTDECLNODE *ppNew);
|
---|
612 |
|
---|
613 | /* ******************************************************************
|
---|
614 | *
|
---|
615 | * DOM parser APIs
|
---|
616 | *
|
---|
617 | ********************************************************************/
|
---|
618 |
|
---|
619 | /*
|
---|
620 | *@@ XMLDOM:
|
---|
621 | * DOM instance returned by xmlCreateDOM.
|
---|
622 | *
|
---|
623 | *@@added V0.9.9 (2001-02-14) [umoeller]
|
---|
624 | */
|
---|
625 |
|
---|
626 | typedef struct _XMLDOM
|
---|
627 | {
|
---|
628 | /*
|
---|
629 | * Public fields (should be read only)
|
---|
630 | */
|
---|
631 |
|
---|
632 | PDOMDOCUMENTNODE pDocumentNode;
|
---|
633 | // document node (contains all the elements)
|
---|
634 |
|
---|
635 | PDOMDOCTYPENODE pDocTypeNode;
|
---|
636 | // != NULL only if the document has a DOCTYPE
|
---|
637 |
|
---|
638 | APIRET arcDOM; // validation errors etc.
|
---|
639 | BOOL fInvalid; // TRUE after validation failed
|
---|
640 |
|
---|
641 | const char *pcszErrorDescription;
|
---|
642 | ULONG ulErrorLine;
|
---|
643 | ULONG ulErrorColumn;
|
---|
644 | PXSTRING pxstrFailingNode; // element or attribute name
|
---|
645 |
|
---|
646 | /*
|
---|
647 | * Private fields (for xml* functions)
|
---|
648 | */
|
---|
649 |
|
---|
650 | XML_Parser pParser;
|
---|
651 | // expat parser instance
|
---|
652 |
|
---|
653 | LINKLIST llElementStack;
|
---|
654 | // stack for maintaining the current items;
|
---|
655 | // these point to DOMSTACKITEMs (auto-free)
|
---|
656 |
|
---|
657 | PDOMNODE pLastWasTextNode;
|
---|
658 |
|
---|
659 | PCMATTRIBUTEDECLBASE pAttListDeclCache;
|
---|
660 | // cache for attribute declarations according
|
---|
661 | // to attdecl element name
|
---|
662 | } XMLDOM, *PXMLDOM;
|
---|
663 |
|
---|
664 | #define DF_PARSECOMMENTS 0x0001
|
---|
665 | #define DF_PARSEDTD 0x0002
|
---|
666 | #define DF_FAIL_IF_NO_DTD 0x0004
|
---|
667 |
|
---|
668 | APIRET xmlCreateDOM(ULONG flParserFlags,
|
---|
669 | PXMLDOM *ppDom);
|
---|
670 |
|
---|
671 | APIRET xmlParse(PXMLDOM pDom,
|
---|
672 | const char *pcszBuf,
|
---|
673 | ULONG cb,
|
---|
674 | BOOL fIsLast);
|
---|
675 |
|
---|
676 | APIRET xmlFreeDOM(PXMLDOM pDom);
|
---|
677 |
|
---|
678 | /* ******************************************************************
|
---|
679 | *
|
---|
680 | * DOM lookup
|
---|
681 | *
|
---|
682 | ********************************************************************/
|
---|
683 |
|
---|
684 | PCMELEMENTDECLNODE xmlFindElementDecl(PXMLDOM pDom,
|
---|
685 | const XSTRING *pstrElementName);
|
---|
686 |
|
---|
687 | PCMATTRIBUTEDECLBASE xmlFindAttribDeclBase(PXMLDOM pDom,
|
---|
688 | const XSTRING *pstrElementName);
|
---|
689 |
|
---|
690 | PCMATTRIBUTEDECL xmlFindAttribDecl(PXMLDOM pDom,
|
---|
691 | const XSTRING *pstrElementName,
|
---|
692 | const XSTRING *pstrAttribName,
|
---|
693 | PCMATTRIBUTEDECLBASE *ppAttribDeclBase);
|
---|
694 |
|
---|
695 | PDOMNODE xmlGetRootElement(PXMLDOM pDom);
|
---|
696 |
|
---|
697 | PDOMNODE xmlGetFirstChild(PDOMNODE pDomNode);
|
---|
698 |
|
---|
699 | PDOMNODE xmlGetLastChild(PDOMNODE pDomNode);
|
---|
700 |
|
---|
701 | PDOMNODE xmlGetFirstText(PDOMNODE pElement);
|
---|
702 |
|
---|
703 | PLINKLIST xmlGetElementsByTagName(PDOMNODE pParent,
|
---|
704 | const char *pcszName);
|
---|
705 |
|
---|
706 | const XSTRING* xmlGetAttribute(PDOMNODE pElement,
|
---|
707 | const char *pcszAttribName);
|
---|
708 |
|
---|
709 | /* ******************************************************************
|
---|
710 | *
|
---|
711 | * DOM build
|
---|
712 | *
|
---|
713 | ********************************************************************/
|
---|
714 |
|
---|
715 | APIRET xmlCreateDocument(const char *pcszRootElementName,
|
---|
716 | PDOMDOCUMENTNODE *ppDocument,
|
---|
717 | PDOMNODE *ppRootElement);
|
---|
718 |
|
---|
719 | APIRET xmlWriteDocument(PDOMDOCUMENTNODE pDocument,
|
---|
720 | const char *pcszEncoding,
|
---|
721 | const char *pcszDoctype,
|
---|
722 | PXSTRING pxstr);
|
---|
723 | #endif
|
---|
724 |
|
---|
725 | #if __cplusplus
|
---|
726 | }
|
---|
727 | #endif
|
---|
728 |
|
---|