source: trunk/third/libxml/tree.h @ 16738

Revision 16738, 16.6 KB checked in by ghudson, 23 years ago (diff)
This commit was generated by cvs2svn to compensate for changes in r16737, which included commits to RCS files with non-trunk default branches.
Line 
1/*
2 * tree.h : describes the structures found in an tree resulting
3 *          from an XML parsing.
4 *
5 * See Copyright for the status of this software.
6 *
7 * Daniel.Veillard@w3.org
8 */
9
10#ifndef __XML_TREE_H__
11#define __XML_TREE_H__
12
13#include <stdio.h>
14
15
16#ifdef __cplusplus
17extern "C" {
18#endif
19
20/*
21 * use those to be sure nothing nasty will happen if
22 * your library and includes mismatch
23 */
24extern void xmlCheckVersion(int version);
25#define LIBXML_VERSION_NUMBER 10808
26#define LIBXML_TEST_VERSION xmlCheckVersion(LIBXML_VERSION_NUMBER);
27
28
29/*
30 * The different element types carried by an XML tree
31 *
32 * NOTE: This is synchronized with DOM Level1 values
33 *       See http://www.w3.org/TR/REC-DOM-Level-1/
34 */
35typedef enum {
36    XML_ELEMENT_NODE=           1,
37    XML_ATTRIBUTE_NODE=         2,
38    XML_TEXT_NODE=              3,
39    XML_CDATA_SECTION_NODE=     4,
40    XML_ENTITY_REF_NODE=        5,
41    XML_ENTITY_NODE=            6,
42    XML_PI_NODE=                7,
43    XML_COMMENT_NODE=           8,
44    XML_DOCUMENT_NODE=          9,
45    XML_DOCUMENT_TYPE_NODE=     10,
46    XML_DOCUMENT_FRAG_NODE=     11,
47    XML_NOTATION_NODE=          12,
48    XML_HTML_DOCUMENT_NODE=     13
49} xmlElementType;
50
51/*
52 * Size of an internal character representation.
53 *
54 * Currently we use 8bit chars internal representation for memory efficiency,
55 * but the parser is not tied to that, just define UNICODE to switch to
56 * a 16 bits internal representation. Note that with 8 bits wide
57 * xmlChars one can still use UTF-8 to handle correctly non ISO-Latin
58 * input.
59 */
60
61#ifdef UNICODE
62typedef unsigned short xmlChar;
63#else
64typedef unsigned char xmlChar;
65#endif
66
67#ifndef WIN32
68#ifndef CHAR
69#define CHAR xmlChar
70#endif
71#endif
72
73#define BAD_CAST (xmlChar *)
74
75/*
76 * a DTD Notation definition
77 */
78
79typedef struct _xmlNotation xmlNotation;
80typedef xmlNotation *xmlNotationPtr;
81struct _xmlNotation {
82    const xmlChar               *name;  /* Notation name */
83    const xmlChar               *PublicID;      /* Public identifier, if any */
84    const xmlChar               *SystemID;      /* System identifier, if any */
85};
86
87/*
88 * a DTD Attribute definition
89 */
90
91typedef enum {
92    XML_ATTRIBUTE_CDATA = 1,
93    XML_ATTRIBUTE_ID,
94    XML_ATTRIBUTE_IDREF ,
95    XML_ATTRIBUTE_IDREFS,
96    XML_ATTRIBUTE_ENTITY,
97    XML_ATTRIBUTE_ENTITIES,
98    XML_ATTRIBUTE_NMTOKEN,
99    XML_ATTRIBUTE_NMTOKENS,
100    XML_ATTRIBUTE_ENUMERATION,
101    XML_ATTRIBUTE_NOTATION
102} xmlAttributeType;
103
104typedef enum {
105    XML_ATTRIBUTE_NONE = 1,
106    XML_ATTRIBUTE_REQUIRED,
107    XML_ATTRIBUTE_IMPLIED,
108    XML_ATTRIBUTE_FIXED
109} xmlAttributeDefault;
110
111typedef struct _xmlEnumeration xmlEnumeration;
112typedef xmlEnumeration *xmlEnumerationPtr;
113struct _xmlEnumeration {
114    struct _xmlEnumeration    *next;    /* next one */
115    const xmlChar            *name;     /* Enumeration name */
116};
117
118typedef struct _xmlAttribute xmlAttribute;
119typedef xmlAttribute *xmlAttributePtr;
120struct _xmlAttribute {
121    const xmlChar         *elem;        /* Element holding the attribute */
122    const xmlChar         *name;        /* Attribute name */
123    struct _xmlAttribute   *next;       /* list of attributes of an element */
124    xmlAttributeType       type;        /* The type */
125    xmlAttributeDefault    def;         /* the default */
126    const xmlChar         *defaultValue;/* or the default value */
127    xmlEnumerationPtr      tree;        /* or the enumeration tree if any */
128    const xmlChar         *prefix;      /* the namespace prefix if any */
129};
130
131/*
132 * a DTD Element definition.
133 */
134typedef enum {
135    XML_ELEMENT_CONTENT_PCDATA = 1,
136    XML_ELEMENT_CONTENT_ELEMENT,
137    XML_ELEMENT_CONTENT_SEQ,
138    XML_ELEMENT_CONTENT_OR
139} xmlElementContentType;
140
141typedef enum {
142    XML_ELEMENT_CONTENT_ONCE = 1,
143    XML_ELEMENT_CONTENT_OPT,
144    XML_ELEMENT_CONTENT_MULT,
145    XML_ELEMENT_CONTENT_PLUS
146} xmlElementContentOccur;
147
148typedef struct _xmlElementContent xmlElementContent;
149typedef xmlElementContent *xmlElementContentPtr;
150struct _xmlElementContent {
151    xmlElementContentType     type;     /* PCDATA, ELEMENT, SEQ or OR */
152    xmlElementContentOccur    ocur;     /* ONCE, OPT, MULT or PLUS */
153    const xmlChar            *name;     /* Element name */
154    struct _xmlElementContent *c1;      /* first child */
155    struct _xmlElementContent *c2;      /* second child */
156};
157
158typedef enum {
159    XML_ELEMENT_TYPE_EMPTY = 1,
160    XML_ELEMENT_TYPE_ANY,
161    XML_ELEMENT_TYPE_MIXED,
162    XML_ELEMENT_TYPE_ELEMENT
163} xmlElementTypeVal;
164
165typedef struct _xmlElement xmlElement;
166typedef xmlElement *xmlElementPtr;
167struct _xmlElement {
168    const xmlChar          *name;       /* Element name */
169    xmlElementTypeVal       type;       /* The type */
170    xmlElementContentPtr content;       /* the allowed element content */
171    xmlAttributePtr   attributes;       /* List of the declared attributes */
172};
173
174/*
175 * An XML namespace.
176 * Note that prefix == NULL is valid, it defines the default namespace
177 * within the subtree (until overriden).
178 */
179
180typedef enum {
181    XML_GLOBAL_NAMESPACE = 1,   /* old style global namespace */
182    XML_LOCAL_NAMESPACE         /* new style local scoping */
183} xmlNsType;
184
185typedef struct _xmlNs xmlNs;
186typedef xmlNs *xmlNsPtr;
187struct _xmlNs {
188    struct _xmlNs  *next;       /* next Ns link for this node  */
189    xmlNsType      type;        /* global or local */
190    const xmlChar *href;        /* URL for the namespace */
191    const xmlChar *prefix;      /* prefix for the namespace */
192};
193
194/*
195 * An XML DtD, as defined by <!DOCTYPE.
196 */
197typedef struct _xmlDtd xmlDtd;
198typedef xmlDtd *xmlDtdPtr;
199struct _xmlDtd {
200    const xmlChar *name;        /* Name of the DTD */
201    const xmlChar *ExternalID;  /* External identifier for PUBLIC DTD */
202    const xmlChar *SystemID;    /* URI for a SYSTEM or PUBLIC DTD */
203    void          *notations;   /* Hash table for notations if any */
204    void          *elements;    /* Hash table for elements if any */
205    void          *attributes;  /* Hash table for attributes if any */
206    void          *entities;    /* Hash table for entities if any */
207    /* struct xmlDtd *next;      * next  link for this document  */
208};
209
210/*
211 * A attribute of an XML node.
212 */
213typedef struct _xmlAttr xmlAttr;
214typedef xmlAttr *xmlAttrPtr;
215struct _xmlAttr {
216#ifndef XML_WITHOUT_CORBA
217    void           *_private;   /* for Corba, must be first ! */
218    void           *vepv;       /* for Corba, must be next ! */
219#endif
220    xmlElementType  type;       /* XML_ATTRIBUTE_NODE, must be third ! */
221    struct _xmlNode *node;      /* attr->node link */
222    struct _xmlAttr *next;      /* attribute list link */
223    const xmlChar   *name;      /* the name of the property */
224    struct _xmlNode *val;       /* the value of the property */
225    xmlNs           *ns;        /* pointer to the associated namespace */
226};
227
228/*
229 * An XML ID instance.
230 */
231
232typedef struct _xmlID xmlID;
233typedef xmlID *xmlIDPtr;
234struct _xmlID {
235    struct _xmlID    *next;     /* next ID */
236    const xmlChar    *value;    /* The ID name */
237    xmlAttrPtr        attr;     /* The attribut holding it */
238};
239
240/*
241 * An XML IDREF instance.
242 */
243
244typedef struct _xmlRef xmlRef;
245typedef xmlRef *xmlRefPtr;
246struct _xmlRef {
247    struct _xmlRef    *next;    /* next Ref */
248    const xmlChar     *value;   /* The Ref name */
249    xmlAttrPtr        attr;     /* The attribut holding it */
250};
251
252/*
253 * A buffer structure
254 */
255
256typedef enum {
257    XML_BUFFER_ALLOC_DOUBLEIT,
258    XML_BUFFER_ALLOC_EXACT
259} xmlBufferAllocationScheme;
260
261typedef struct _xmlBuffer xmlBuffer;
262typedef xmlBuffer *xmlBufferPtr;
263struct _xmlBuffer {
264    xmlChar *content;           /* The buffer content UTF8 */
265    unsigned int use;           /* The buffer size used */
266    unsigned int size;          /* The buffer size */
267    xmlBufferAllocationScheme alloc; /* The realloc method */
268};
269
270/*
271 * A node in an XML tree.
272 */
273typedef struct _xmlNode xmlNode;
274typedef xmlNode *xmlNodePtr;
275struct _xmlNode {
276#ifndef XML_WITHOUT_CORBA
277    void           *_private;   /* for Corba, must be first ! */
278    void           *vepv;       /* for Corba, must be next ! */
279#endif
280    xmlElementType  type;       /* type number in the DTD, must be third ! */
281    struct _xmlDoc  *doc;       /* the containing document */
282    struct _xmlNode *parent;    /* child->parent link */
283    struct _xmlNode *next;      /* next sibling link  */
284    struct _xmlNode *prev;      /* previous sibling link  */
285    struct _xmlNode *childs;    /* parent->childs link */
286    struct _xmlNode *last;      /* last child link */
287    struct _xmlAttr *properties;/* properties list */
288    const xmlChar  *name;       /* the name of the node, or the entity */
289    xmlNs          *ns;         /* pointer to the associated namespace */
290    xmlNs          *nsDef;      /* namespace definitions on this node */
291#ifndef XML_USE_BUFFER_CONTENT   
292    xmlChar        *content;    /* the content */
293#else
294    xmlBufferPtr   content;     /* the content in a buffer */
295#endif
296};
297
298/*
299 * An XML document.
300 */
301typedef struct _xmlDoc xmlDoc;
302typedef xmlDoc *xmlDocPtr;
303struct _xmlDoc {
304#ifndef XML_WITHOUT_CORBA
305    void           *_private;   /* for Corba, must be first ! */
306    void           *vepv;       /* for Corba, must be next ! */
307#endif
308    xmlElementType  type;       /* XML_DOCUMENT_NODE, must be second ! */
309    char           *name;       /* name/filename/URI of the document */
310    const xmlChar  *version;    /* the XML version string */
311    const xmlChar  *encoding;   /* encoding, if any */
312    int             compression;/* level of zlib compression */
313    int             standalone; /* standalone document (no external refs) */
314    struct _xmlDtd  *intSubset; /* the document internal subset */
315    struct _xmlDtd  *extSubset; /* the document external subset */
316    struct _xmlNs   *oldNs;     /* Global namespace, the old way */
317    struct _xmlNode *root;      /* the document tree */
318    void           *ids;        /* Hash table for ID attributes if any */
319    void           *refs;       /* Hash table for IDREFs attributes if any */
320};
321
322/*
323 * Compatibility naming layer with libxml1
324 */
325#ifndef xmlChildrenNode
326#define xmlChildrenNode childs
327#define xmlRootNode root
328#endif
329
330/*
331 * Variables.
332 */
333extern xmlNsPtr baseDTD;
334extern int oldXMLWDcompatibility;/* maintain compatibility with old WD */
335extern int xmlIndentTreeOutput;  /* try to indent the tree dumps */
336extern xmlBufferAllocationScheme xmlBufferAllocScheme; /* alloc scheme to use */
337extern int xmlSaveNoEmptyTags;   /* save empty tags as <empty></empty> */
338
339/*
340 * Handling Buffers.
341 */
342
343xmlBufferPtr    xmlBufferCreate         (void);
344xmlBufferPtr    xmlBufferCreateSize     (size_t size);
345void            xmlBufferFree           (xmlBufferPtr buf);
346int             xmlBufferDump           (FILE *file,
347                                         xmlBufferPtr buf);
348void            xmlBufferAdd            (xmlBufferPtr buf,
349                                         const xmlChar *str,
350                                         int len);
351void            xmlBufferCat            (xmlBufferPtr buf,
352                                         const xmlChar *str);
353void            xmlBufferCCat           (xmlBufferPtr buf,
354                                         const char *str);
355int             xmlBufferShrink         (xmlBufferPtr buf,
356                                         int len);
357void            xmlBufferEmpty          (xmlBufferPtr buf);
358const xmlChar*  xmlBufferContent        (const xmlBufferPtr buf);
359int             xmlBufferUse            (const xmlBufferPtr buf);
360void            xmlBufferSetAllocationScheme(xmlBufferPtr buf,
361                                         xmlBufferAllocationScheme scheme);
362int             xmlBufferLength         (const xmlBufferPtr buf);
363
364/*
365 * Creating/freeing new structures
366 */
367xmlDtdPtr       xmlCreateIntSubset      (xmlDocPtr doc,
368                                         const xmlChar *name,
369                                         const xmlChar *ExternalID,
370                                         const xmlChar *SystemID);
371xmlDtdPtr       xmlNewDtd               (xmlDocPtr doc,
372                                         const xmlChar *name,
373                                         const xmlChar *ExternalID,
374                                         const xmlChar *SystemID);
375void            xmlFreeDtd              (xmlDtdPtr cur);
376xmlNsPtr        xmlNewGlobalNs          (xmlDocPtr doc,
377                                         const xmlChar *href,
378                                         const xmlChar *prefix);
379xmlNsPtr        xmlNewNs                (xmlNodePtr node,
380                                         const xmlChar *href,
381                                         const xmlChar *prefix);
382void            xmlFreeNs               (xmlNsPtr cur);
383xmlDocPtr       xmlNewDoc               (const xmlChar *version);
384void            xmlFreeDoc              (xmlDocPtr cur);
385xmlAttrPtr      xmlNewDocProp           (xmlDocPtr doc,
386                                         const xmlChar *name,
387                                         const xmlChar *value);
388xmlAttrPtr      xmlNewProp              (xmlNodePtr node,
389                                         const xmlChar *name,
390                                         const xmlChar *value);
391xmlAttrPtr      xmlNewNsProp            (xmlNodePtr node,
392                                         xmlNsPtr ns,
393                                         const xmlChar *name,
394                                         const xmlChar *value);
395void            xmlFreePropList         (xmlAttrPtr cur);
396void            xmlFreeProp             (xmlAttrPtr cur);
397xmlAttrPtr      xmlCopyProp             (xmlNodePtr target,
398                                         xmlAttrPtr cur);
399xmlAttrPtr      xmlCopyPropList         (xmlNodePtr target,
400                                         xmlAttrPtr cur);
401xmlDtdPtr       xmlCopyDtd              (xmlDtdPtr dtd);
402xmlDocPtr       xmlCopyDoc              (xmlDocPtr doc,
403                                         int recursive);
404
405/*
406 * Creating new nodes
407 */
408xmlNodePtr      xmlNewDocNode           (xmlDocPtr doc,
409                                         xmlNsPtr ns,
410                                         const xmlChar *name,
411                                         const xmlChar *content);
412xmlNodePtr      xmlNewDocRawNode        (xmlDocPtr doc,
413                                         xmlNsPtr ns,
414                                         const xmlChar *name,
415                                         const xmlChar *content);
416xmlNodePtr      xmlNewNode              (xmlNsPtr ns,
417                                         const xmlChar *name);
418xmlNodePtr      xmlNewChild             (xmlNodePtr parent,
419                                         xmlNsPtr ns,
420                                         const xmlChar *name,
421                                         const xmlChar *content);
422xmlNodePtr      xmlNewTextChild         (xmlNodePtr parent,
423                                         xmlNsPtr ns,
424                                         const xmlChar *name,
425                                         const xmlChar *content);
426xmlNodePtr      xmlNewDocText           (xmlDocPtr doc,
427                                         const xmlChar *content);
428xmlNodePtr      xmlNewText              (const xmlChar *content);
429xmlNodePtr      xmlNewPI                (const xmlChar *name,
430                                         const xmlChar *content);
431xmlNodePtr      xmlNewDocTextLen        (xmlDocPtr doc,
432                                         const xmlChar *content,
433                                         int len);
434xmlNodePtr      xmlNewTextLen           (const xmlChar *content,
435                                         int len);
436xmlNodePtr      xmlNewDocComment        (xmlDocPtr doc,
437                                         const xmlChar *content);
438xmlNodePtr      xmlNewComment           (const xmlChar *content);
439xmlNodePtr      xmlNewCDataBlock        (xmlDocPtr doc,
440                                         const xmlChar *content,
441                                         int len);
442xmlNodePtr      xmlNewReference         (xmlDocPtr doc,
443                                         const xmlChar *name);
444xmlNodePtr      xmlCopyNode             (xmlNodePtr node,
445                                         int recursive);
446xmlNodePtr      xmlCopyNodeList         (xmlNodePtr node);
447xmlNodePtr      xmlNewDocFragment       (xmlDocPtr doc);
448
449/*
450 * Navigating
451 */
452xmlNodePtr      xmlDocGetRootElement    (xmlDocPtr doc);
453xmlNodePtr      xmlGetLastChild         (xmlNodePtr parent);
454int             xmlNodeIsText           (xmlNodePtr node);
455int             xmlIsBlankNode          (xmlNodePtr node);
456
457/*
458 * Changing the structure
459 */
460xmlNodePtr      xmlDocSetRootElement    (xmlDocPtr doc,
461                                         xmlNodePtr root);
462void            xmlNodeSetName          (xmlNodePtr cur,
463                                         const xmlChar *name);
464xmlNodePtr      xmlAddChild             (xmlNodePtr parent,
465                                         xmlNodePtr cur);
466xmlNodePtr      xmlReplaceNode          (xmlNodePtr old,
467                                         xmlNodePtr cur);
468xmlNodePtr      xmlAddSibling           (xmlNodePtr cur,
469                                         xmlNodePtr elem);
470xmlNodePtr      xmlAddPrevSibling       (xmlNodePtr cur,
471                                         xmlNodePtr elem);
472xmlNodePtr      xmlAddNextSibling       (xmlNodePtr cur,
473                                         xmlNodePtr elem);
474void            xmlUnlinkNode           (xmlNodePtr cur);
475xmlNodePtr      xmlTextMerge            (xmlNodePtr first,
476                                         xmlNodePtr second);
477void            xmlTextConcat           (xmlNodePtr node,
478                                         const xmlChar *content,
479                                         int len);
480void            xmlFreeNodeList         (xmlNodePtr cur);
481void            xmlFreeNode             (xmlNodePtr cur);
482
483/*
484 * Namespaces
485 */
486xmlNsPtr        xmlSearchNs             (xmlDocPtr doc,
487                                         xmlNodePtr node,
488                                         const xmlChar *nameSpace);
489xmlNsPtr        xmlSearchNsByHref       (xmlDocPtr doc,
490                                         xmlNodePtr node,
491                                         const xmlChar *href);
492xmlNsPtr *      xmlGetNsList            (xmlDocPtr doc,
493                                         xmlNodePtr node);
494void            xmlSetNs                (xmlNodePtr node,
495                                         xmlNsPtr ns);
496xmlNsPtr        xmlCopyNamespace        (xmlNsPtr cur);
497xmlNsPtr        xmlCopyNamespaceList    (xmlNsPtr cur);
498
499/*
500 * Changing the content.
501 */
502xmlAttrPtr      xmlSetProp              (xmlNodePtr node,
503                                         const xmlChar *name,
504                                         const xmlChar *value);
505xmlChar *       xmlGetProp              (xmlNodePtr node,
506                                         const xmlChar *name);
507xmlChar *       xmlGetNsProp            (xmlNodePtr node,
508                                         const xmlChar *name,
509                                         const xmlChar *nameSpace);
510xmlNodePtr      xmlStringGetNodeList    (xmlDocPtr doc,
511                                         const xmlChar *value);
512xmlNodePtr      xmlStringLenGetNodeList (xmlDocPtr doc,
513                                         const xmlChar *value,
514                                         int len);
515xmlChar *       xmlNodeListGetString    (xmlDocPtr doc,
516                                         xmlNodePtr list,
517                                         int inLine);
518void            xmlNodeSetContent       (xmlNodePtr cur,
519                                         const xmlChar *content);
520void            xmlNodeSetContentLen    (xmlNodePtr cur,
521                                         const xmlChar *content,
522                                         int len);
523void            xmlNodeAddContent       (xmlNodePtr cur,
524                                         const xmlChar *content);
525void            xmlNodeAddContentLen    (xmlNodePtr cur,
526                                         const xmlChar *content,
527                                         int len);
528xmlChar *       xmlNodeGetContent       (xmlNodePtr cur);
529xmlChar *       xmlNodeGetLang          (xmlNodePtr cur);
530void            xmlNodeSetLang          (xmlNodePtr cur,
531                                         const xmlChar *lang);
532xmlChar *       xmlNodeGetBase          (xmlDocPtr doc,
533                                         xmlNodePtr cur);
534
535/*
536 * Removing content.
537 */
538int             xmlRemoveProp           (xmlAttrPtr cur);
539int             xmlRemoveNode           (xmlNodePtr node); /* TODO */
540
541/*
542 * Internal, don't use
543 */
544void            xmlBufferWriteCHAR      (xmlBufferPtr buf,
545                                         const xmlChar *string);
546void            xmlBufferWriteChar      (xmlBufferPtr buf,
547                                         const char *string);
548void            xmlBufferWriteQuotedString(xmlBufferPtr buf,
549                                         const xmlChar *string);
550
551/*
552 * Saving
553 */
554void            xmlDocDumpMemory        (xmlDocPtr cur,
555                                         xmlChar**mem,
556                                         int *size);
557void            xmlDocDump              (FILE *f,
558                                         xmlDocPtr cur);
559void            xmlElemDump             (FILE *f,
560                                         xmlDocPtr cur,
561                                         xmlNodePtr elem);
562int             xmlSaveFile             (const char *filename,
563                                         xmlDocPtr cur);
564
565/*
566 * Compression
567 */
568int             xmlGetDocCompressMode   (xmlDocPtr doc);
569void            xmlSetDocCompressMode   (xmlDocPtr doc,
570                                         int mode);
571int             xmlGetCompressMode      (void);
572void            xmlSetCompressMode      (int mode);
573
574#ifdef __cplusplus
575}
576#endif
577
578#endif /* __XML_TREE_H__ */
579
Note: See TracBrowser for help on using the repository browser.