blob: 91677a618e2b95444a1adca687ad0377b8995a19 [file] [log] [blame]
Daniel Veillard260a68f1998-08-13 03:39:55 +00001/*
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 * $Id$
8 */
9
10#ifndef __XML_TREE_H__
11#define __XML_TREE_H__
12
13
14#ifdef __cplusplus
15extern "C" {
16#endif
17
18/*
19 * Type definitions
20 */
21#ifdef UNICODE
22typedef unsigned short CHAR;
23#else
24typedef unsigned char CHAR;
25#endif
26
27/*
28 * a DTD Notation definition
29 * TODO !!!!
30 */
31
32/*
33 * a DTD Attribute definition
34 * TODO !!!!
35 */
36
37/*
38 * a DTD Element definition.
39 */
40#define XML_ELEMENT_TYPE_EMPTY 1
41#define XML_ELEMENT_TYPE_ANY 2
42#define XML_ELEMENT_TYPE_MIXED 3
43#define XML_ELEMENT_TYPE_ELEMENT 4
44
45typedef struct xmlElement {
46 const CHAR *name; /* Element name */
47 int type; /* type (too simple, to extend ...) */
48 /* TODO !!! more needed */
49} xmlElement, *xmlElementPtr;
50
51/*
52 * An XML namespace.
53 * Note that prefix == NULL is valid, it defines the default namespace
54 * within the subtree (until overriden).
55 */
56
57#define XML_GLOBAL_NAMESPACE 1 /* old style global namespace */
58#define XML_LOCAL_NAMESPACE 2 /* new style local scoping */
59
60typedef struct xmlNs {
61 struct xmlNs *next; /* next Ns link for this node */
62 int type; /* global or local */
63 const CHAR *href; /* URL for the namespace */
64 const CHAR *prefix; /* prefix for the namespace */
65} xmlNs, *xmlNsPtr;
66
67/*
68 * An XML DtD, as defined by <!DOCTYPE.
69 */
70typedef struct xmlDtd {
71 const CHAR *name; /* Name of the DTD */
72 const CHAR *ExternalID; /* External identifier for PUBLIC DTD */
73 const CHAR *SystemID; /* URI for a SYSTEM or PUBLIC DTD */
74 void *elements; /* Hash table for elements if any */
75 void *entities; /* Hash table for entities if any */
76 /* struct xmlDtd *next; * next link for this document */
77} xmlDtd, *xmlDtdPtr;
78
79/*
80 * A attribute of an XML node.
81 */
82typedef struct xmlAttr {
Daniel Veillard27fb0751998-10-17 06:47:46 +000083#ifndef XML_WITHOUT_CORBA
84 void *_private; /* for Corba, must be first ! */
85 void *vepv; /* for Corba, must be next ! */
86#endif
87 int type; /* XML_ATTRIBUTE_NODE, must be third ! */
Daniel Veillard260a68f1998-08-13 03:39:55 +000088 struct xmlNode *node; /* attr->node link */
89 struct xmlAttr *next; /* parent->childs link */
90 const CHAR *name; /* the name of the property */
91 const CHAR *value; /* the value of the property */
92} xmlAttr, *xmlAttrPtr;
93
94/*
95 * A node in an XML tree.
Daniel Veillard0bef1311998-10-14 02:36:47 +000096 * NOTE: This is synchronized with DOM Level1 values
97 * See http://www.w3.org/TR/REC-DOM-Level-1/
Daniel Veillard260a68f1998-08-13 03:39:55 +000098 */
Daniel Veillard0bef1311998-10-14 02:36:47 +000099#define XML_ELEMENT_NODE 1
100#define XML_ATTRIBUTE_NODE 2
101#define XML_TEXT_NODE 3
102#define XML_CDATA_SECTION_NODE 4
103#define XML_ENTITY_REF_NODE 5
104#define XML_ENTITY_NODE 6
105#define XML_PI_NODE 7
106#define XML_COMMENT_NODE 8
107#define XML_DOCUMENT_NODE 9
108#define XML_DOCUMENT_TYPE_NODE 10
109#define XML_DOCUMENT_FRAG_NODE 11
110#define XML_NOTATION_NODE 12
Daniel Veillard260a68f1998-08-13 03:39:55 +0000111
112typedef struct xmlNode {
Daniel Veillard27fb0751998-10-17 06:47:46 +0000113#ifndef XML_WITHOUT_CORBA
114 void *_private; /* for Corba, must be first ! */
115 void *vepv; /* for Corba, must be next ! */
116#endif
117 int type; /* type number in the DTD, must be third ! */
Daniel Veillard0bef1311998-10-14 02:36:47 +0000118 struct xmlDoc *doc; /* the containing document */
Daniel Veillard260a68f1998-08-13 03:39:55 +0000119 struct xmlNode *parent; /* child->parent link */
120 struct xmlNode *next; /* next sibling link */
Daniel Veillard0bef1311998-10-14 02:36:47 +0000121 struct xmlNode *prev; /* previous sibling link */
Daniel Veillard260a68f1998-08-13 03:39:55 +0000122 struct xmlNode *childs; /* parent->childs link */
123 struct xmlAttr *properties; /* properties list */
Daniel Veillard260a68f1998-08-13 03:39:55 +0000124 const CHAR *name; /* the name of the node, or the entity */
125 xmlNs *ns; /* pointer to the associated namespace */
126 xmlNs *nsDef; /* namespace definitions on this node */
127 CHAR *content; /* the content */
128} xmlNode, *xmlNodePtr;
129
130/*
131 * An XML document.
132 */
133typedef struct xmlDoc {
Daniel Veillard27fb0751998-10-17 06:47:46 +0000134#ifndef XML_WITHOUT_CORBA
135 void *_private; /* for Corba, must be first ! */
136 void *vepv; /* for Corba, must be next ! */
137#endif
138 int type; /* XML_DOCUMENT_NODE, must be second ! */
Daniel Veillard260a68f1998-08-13 03:39:55 +0000139 char *name; /* name/filename/URI of the document */
140 const CHAR *version; /* the XML version string */
141 const CHAR *encoding; /* encoding, if any */
Daniel Veillard15a8df41998-09-24 19:15:06 +0000142 int compression;/* level of zlib compression */
Daniel Veillard260a68f1998-08-13 03:39:55 +0000143 int standalone; /* standalone document (no external refs) */
144 struct xmlDtd *dtd; /* the document DTD if available */
145 struct xmlNs *oldNs; /* Global namespace, the old way */
146 void *entities; /* Hash table for general entities if any */
147 struct xmlNode *root; /* the document tree */
148} xmlDoc, *xmlDocPtr;
149
150/*
151 * Variables.
152 */
153extern xmlNsPtr baseDTD;
154extern int oldXMLWDcompatibility;/* maintain compatibility with old WD */
155extern int xmlIndentTreeOutput; /* try to indent the tree dumps */
156
157/*
158 * Functions.
159 */
160extern xmlDtdPtr xmlNewDtd(xmlDocPtr doc, const CHAR *name,
161 const CHAR *ExternalID, const CHAR *SystemID);
162extern void xmlFreeDtd(xmlDtdPtr cur);
163extern xmlNsPtr xmlNewGlobalNs(xmlDocPtr doc, const CHAR *href, const CHAR *AS);
164extern xmlNsPtr xmlNewNs(xmlNodePtr node, const CHAR *href, const CHAR *AS);
165extern void xmlFreeNs(xmlNsPtr cur);
166extern xmlDocPtr xmlNewDoc(const CHAR *version);
167extern void xmlFreeDoc(xmlDocPtr cur);
168extern xmlAttrPtr xmlNewProp(xmlNodePtr node, const CHAR *name,
169 const CHAR *value);
170extern xmlAttrPtr xmlSetProp(xmlNodePtr node, const CHAR *name,
171 const CHAR *value);
172extern const CHAR *xmlGetProp(xmlNodePtr node, const CHAR *name);
173extern void xmlFreePropList(xmlAttrPtr cur);
174extern void xmlFreeProp(xmlAttrPtr cur);
Daniel Veillard0bef1311998-10-14 02:36:47 +0000175extern xmlNodePtr xmlNewDocNode(xmlDocPtr doc, xmlNsPtr ns,
176 const CHAR *name, CHAR *content);
Daniel Veillard260a68f1998-08-13 03:39:55 +0000177extern xmlNodePtr xmlNewNode(xmlNsPtr ns, const CHAR *name, CHAR *content);
Daniel Veillard0bef1311998-10-14 02:36:47 +0000178extern xmlNodePtr xmlNewDocText(xmlDocPtr doc, const CHAR *content);
Daniel Veillard260a68f1998-08-13 03:39:55 +0000179extern xmlNodePtr xmlNewText(const CHAR *content);
Daniel Veillard0bef1311998-10-14 02:36:47 +0000180extern xmlNodePtr xmlNewDocTextLen(xmlDocPtr doc, const CHAR *content, int len);
Daniel Veillard260a68f1998-08-13 03:39:55 +0000181extern xmlNodePtr xmlNewTextLen(const CHAR *content, int len);
Daniel Veillard0bef1311998-10-14 02:36:47 +0000182extern xmlNodePtr xmlNewDocComment(xmlDocPtr doc, CHAR *content);
Daniel Veillard260a68f1998-08-13 03:39:55 +0000183extern xmlNodePtr xmlNewComment(CHAR *content);
184extern xmlNodePtr xmlAddChild(xmlNodePtr parent, xmlNodePtr cur);
185extern xmlNodePtr xmlGetLastChild(xmlNodePtr node);
186extern int xmlNodeIsText(xmlNodePtr node);
187extern void xmlTextConcat(xmlNodePtr node, const CHAR *content, int len);
188extern void xmlFreeNodeList(xmlNodePtr cur);
189extern void xmlFreeNode(xmlNodePtr cur);
190extern void xmlNodeSetContent(xmlNodePtr cur, const CHAR *content);
191extern void xmlNodeSetContentLen(xmlNodePtr cur, const CHAR *content, int len);
192extern void xmlNodeAddContent(xmlNodePtr cur, const CHAR *content);
193extern void xmlNodeAddContentLen(xmlNodePtr cur, const CHAR *content, int len);
194extern xmlNsPtr xmlSearchNs(xmlDocPtr doc, xmlNodePtr node,
195 const CHAR *nameSpace);
196extern xmlNsPtr xmlSearchNsByHref(xmlDocPtr doc, xmlNodePtr node,
197 const CHAR *href);
198extern void xmlSetNs(xmlNodePtr node, xmlNsPtr ns);
199extern xmlNodePtr xmlNewChild(xmlNodePtr parent, xmlNsPtr ns,
200 const CHAR *name, CHAR *content);
Daniel Veillard0bef1311998-10-14 02:36:47 +0000201extern xmlNodePtr xmlNewChild(xmlNodePtr parent, xmlNsPtr ns,
202 const CHAR *name, CHAR *content);
Daniel Veillard260a68f1998-08-13 03:39:55 +0000203
Daniel Veillard260a68f1998-08-13 03:39:55 +0000204extern void xmlBufferWriteCHAR(const CHAR *string);
205extern void xmlBufferWriteChar(const char *string);
206
Daniel Veillard151b1b01998-09-23 00:49:46 +0000207extern void xmlDocDumpMemory(xmlDocPtr cur, CHAR**mem, int *size);
208extern void xmlDocDump(FILE *f, xmlDocPtr doc);
209int xmlSaveFile(const char *filename, xmlDocPtr cur);
210
Daniel Veillard15a8df41998-09-24 19:15:06 +0000211extern int xmlGetDocCompressMode (xmlDocPtr doc);
212extern void xmlSetDocCompressMode (xmlDocPtr doc, int mode);
Daniel Veillard151b1b01998-09-23 00:49:46 +0000213extern int xmlGetCompressMode(void);
214extern void xmlSetCompressMode(int mode);
Daniel Veillard260a68f1998-08-13 03:39:55 +0000215
216#ifdef __cplusplus
217}
218#endif
219
220#endif /* __XML_TREE_H__ */
221