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