blob: e3764d8be3377100a31cbb66b0e945550f14cc2b [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/*
Daniel Veillardccb09631998-10-27 06:21:04 +000019 * The different element types carried by an XML tree
20 *
21 * NOTE: This is synchronized with DOM Level1 values
22 * See http://www.w3.org/TR/REC-DOM-Level-1/
23 */
24typedef enum {
25 XML_ELEMENT_NODE= 1,
26 XML_ATTRIBUTE_NODE= 2,
27 XML_TEXT_NODE= 3,
28 XML_CDATA_SECTION_NODE= 4,
29 XML_ENTITY_REF_NODE= 5,
30 XML_ENTITY_NODE= 6,
31 XML_PI_NODE= 7,
32 XML_COMMENT_NODE= 8,
33 XML_DOCUMENT_NODE= 9,
34 XML_DOCUMENT_TYPE_NODE= 10,
35 XML_DOCUMENT_FRAG_NODE= 11,
36 XML_NOTATION_NODE= 12
37} xmlElementType;
38
39/*
Daniel Veillard0ba4d531998-11-01 19:34:31 +000040 * Size of an internal character representation.
41 *
42 * Currently we use 8bit chars internal representation for memory efficiency,
43 * but the parser is not tied to that, just define UNICODE to switch to
44 * a 16 bits internal representation. Note that with 8 bits wide
45 * CHARs one can still use UTF-8 to handle correctly non ISO-Latin
46 * input.
Daniel Veillard260a68f1998-08-13 03:39:55 +000047 */
48#ifdef UNICODE
49typedef unsigned short CHAR;
50#else
51typedef unsigned char CHAR;
52#endif
53
54/*
55 * a DTD Notation definition
56 * TODO !!!!
57 */
58
59/*
60 * a DTD Attribute definition
61 * TODO !!!!
62 */
63
64/*
65 * a DTD Element definition.
66 */
67#define XML_ELEMENT_TYPE_EMPTY 1
68#define XML_ELEMENT_TYPE_ANY 2
69#define XML_ELEMENT_TYPE_MIXED 3
70#define XML_ELEMENT_TYPE_ELEMENT 4
71
72typedef struct xmlElement {
73 const CHAR *name; /* Element name */
74 int type; /* type (too simple, to extend ...) */
75 /* TODO !!! more needed */
76} xmlElement, *xmlElementPtr;
77
78/*
79 * An XML namespace.
80 * Note that prefix == NULL is valid, it defines the default namespace
81 * within the subtree (until overriden).
82 */
83
84#define XML_GLOBAL_NAMESPACE 1 /* old style global namespace */
85#define XML_LOCAL_NAMESPACE 2 /* new style local scoping */
86
87typedef struct xmlNs {
88 struct xmlNs *next; /* next Ns link for this node */
89 int type; /* global or local */
90 const CHAR *href; /* URL for the namespace */
91 const CHAR *prefix; /* prefix for the namespace */
92} xmlNs, *xmlNsPtr;
93
94/*
95 * An XML DtD, as defined by <!DOCTYPE.
96 */
97typedef struct xmlDtd {
98 const CHAR *name; /* Name of the DTD */
99 const CHAR *ExternalID; /* External identifier for PUBLIC DTD */
100 const CHAR *SystemID; /* URI for a SYSTEM or PUBLIC DTD */
101 void *elements; /* Hash table for elements if any */
102 void *entities; /* Hash table for entities if any */
103 /* struct xmlDtd *next; * next link for this document */
104} xmlDtd, *xmlDtdPtr;
105
106/*
107 * A attribute of an XML node.
108 */
109typedef struct xmlAttr {
Daniel Veillard27fb0751998-10-17 06:47:46 +0000110#ifndef XML_WITHOUT_CORBA
111 void *_private; /* for Corba, must be first ! */
112 void *vepv; /* for Corba, must be next ! */
113#endif
Daniel Veillardccb09631998-10-27 06:21:04 +0000114 xmlElementType type; /* XML_ATTRIBUTE_NODE, must be third ! */
Daniel Veillard260a68f1998-08-13 03:39:55 +0000115 struct xmlNode *node; /* attr->node link */
116 struct xmlAttr *next; /* parent->childs link */
117 const CHAR *name; /* the name of the property */
Daniel Veillardccb09631998-10-27 06:21:04 +0000118 struct xmlNode *val; /* the value of the property */
Daniel Veillard260a68f1998-08-13 03:39:55 +0000119} xmlAttr, *xmlAttrPtr;
120
121/*
122 * A node in an XML tree.
123 */
Daniel Veillard260a68f1998-08-13 03:39:55 +0000124typedef struct xmlNode {
Daniel Veillard27fb0751998-10-17 06:47:46 +0000125#ifndef XML_WITHOUT_CORBA
126 void *_private; /* for Corba, must be first ! */
127 void *vepv; /* for Corba, must be next ! */
128#endif
Daniel Veillardccb09631998-10-27 06:21:04 +0000129 xmlElementType type; /* type number in the DTD, must be third ! */
Daniel Veillard0bef1311998-10-14 02:36:47 +0000130 struct xmlDoc *doc; /* the containing document */
Daniel Veillard260a68f1998-08-13 03:39:55 +0000131 struct xmlNode *parent; /* child->parent link */
132 struct xmlNode *next; /* next sibling link */
Daniel Veillard0bef1311998-10-14 02:36:47 +0000133 struct xmlNode *prev; /* previous sibling link */
Daniel Veillard260a68f1998-08-13 03:39:55 +0000134 struct xmlNode *childs; /* parent->childs link */
135 struct xmlAttr *properties; /* properties list */
Daniel Veillard260a68f1998-08-13 03:39:55 +0000136 const CHAR *name; /* the name of the node, or the entity */
137 xmlNs *ns; /* pointer to the associated namespace */
138 xmlNs *nsDef; /* namespace definitions on this node */
139 CHAR *content; /* the content */
140} xmlNode, *xmlNodePtr;
141
142/*
143 * An XML document.
144 */
145typedef struct xmlDoc {
Daniel Veillard27fb0751998-10-17 06:47:46 +0000146#ifndef XML_WITHOUT_CORBA
147 void *_private; /* for Corba, must be first ! */
148 void *vepv; /* for Corba, must be next ! */
149#endif
Daniel Veillardccb09631998-10-27 06:21:04 +0000150 xmlElementType type; /* XML_DOCUMENT_NODE, must be second ! */
Daniel Veillard260a68f1998-08-13 03:39:55 +0000151 char *name; /* name/filename/URI of the document */
152 const CHAR *version; /* the XML version string */
153 const CHAR *encoding; /* encoding, if any */
Daniel Veillard15a8df41998-09-24 19:15:06 +0000154 int compression;/* level of zlib compression */
Daniel Veillard260a68f1998-08-13 03:39:55 +0000155 int standalone; /* standalone document (no external refs) */
156 struct xmlDtd *dtd; /* the document DTD if available */
157 struct xmlNs *oldNs; /* Global namespace, the old way */
158 void *entities; /* Hash table for general entities if any */
159 struct xmlNode *root; /* the document tree */
160} xmlDoc, *xmlDocPtr;
161
162/*
163 * Variables.
164 */
165extern xmlNsPtr baseDTD;
166extern int oldXMLWDcompatibility;/* maintain compatibility with old WD */
167extern int xmlIndentTreeOutput; /* try to indent the tree dumps */
168
169/*
Daniel Veillard16253641998-10-28 22:58:05 +0000170 * Creating/freeing new structures
Daniel Veillard260a68f1998-08-13 03:39:55 +0000171 */
172extern xmlDtdPtr xmlNewDtd(xmlDocPtr doc, const CHAR *name,
173 const CHAR *ExternalID, const CHAR *SystemID);
174extern void xmlFreeDtd(xmlDtdPtr cur);
175extern xmlNsPtr xmlNewGlobalNs(xmlDocPtr doc, const CHAR *href, const CHAR *AS);
176extern xmlNsPtr xmlNewNs(xmlNodePtr node, const CHAR *href, const CHAR *AS);
177extern void xmlFreeNs(xmlNsPtr cur);
178extern xmlDocPtr xmlNewDoc(const CHAR *version);
179extern void xmlFreeDoc(xmlDocPtr cur);
Daniel Veillardccb09631998-10-27 06:21:04 +0000180extern xmlAttrPtr xmlNewDocProp(xmlDocPtr doc, const CHAR *name,
181 const CHAR *value);
Daniel Veillard260a68f1998-08-13 03:39:55 +0000182extern xmlAttrPtr xmlNewProp(xmlNodePtr node, const CHAR *name,
183 const CHAR *value);
Daniel Veillard260a68f1998-08-13 03:39:55 +0000184extern void xmlFreePropList(xmlAttrPtr cur);
185extern void xmlFreeProp(xmlAttrPtr cur);
Daniel Veillard16253641998-10-28 22:58:05 +0000186
187/*
188 * Creating new nodes
189 */
Daniel Veillard0bef1311998-10-14 02:36:47 +0000190extern xmlNodePtr xmlNewDocNode(xmlDocPtr doc, xmlNsPtr ns,
191 const CHAR *name, CHAR *content);
Daniel Veillardccb09631998-10-27 06:21:04 +0000192extern xmlNodePtr xmlNewNode(xmlNsPtr ns, const CHAR *name);
Daniel Veillard16253641998-10-28 22:58:05 +0000193extern xmlNodePtr xmlNewChild(xmlNodePtr parent, xmlNsPtr ns,
194 const CHAR *name, CHAR *content);
Daniel Veillard0bef1311998-10-14 02:36:47 +0000195extern xmlNodePtr xmlNewDocText(xmlDocPtr doc, const CHAR *content);
Daniel Veillard260a68f1998-08-13 03:39:55 +0000196extern xmlNodePtr xmlNewText(const CHAR *content);
Daniel Veillard0bef1311998-10-14 02:36:47 +0000197extern xmlNodePtr xmlNewDocTextLen(xmlDocPtr doc, const CHAR *content, int len);
Daniel Veillard260a68f1998-08-13 03:39:55 +0000198extern xmlNodePtr xmlNewTextLen(const CHAR *content, int len);
Daniel Veillard0bef1311998-10-14 02:36:47 +0000199extern xmlNodePtr xmlNewDocComment(xmlDocPtr doc, CHAR *content);
Daniel Veillard260a68f1998-08-13 03:39:55 +0000200extern xmlNodePtr xmlNewComment(CHAR *content);
Daniel Veillardccb09631998-10-27 06:21:04 +0000201extern xmlNodePtr xmlNewReference(xmlDocPtr doc, const CHAR *name);
Daniel Veillard16253641998-10-28 22:58:05 +0000202
203/*
204 * Navigating
205 */
Daniel Veillard260a68f1998-08-13 03:39:55 +0000206extern xmlNodePtr xmlGetLastChild(xmlNodePtr node);
207extern int xmlNodeIsText(xmlNodePtr node);
Daniel Veillard16253641998-10-28 22:58:05 +0000208
209/*
210 * Changing the structure
211 */
212extern xmlNodePtr xmlAddChild(xmlNodePtr parent, xmlNodePtr cur);
213extern void xmlUnlinkNode(xmlNodePtr cur);
214
215extern xmlNodePtr xmlTextMerge(xmlNodePtr first, xmlNodePtr second);
Daniel Veillard260a68f1998-08-13 03:39:55 +0000216extern void xmlTextConcat(xmlNodePtr node, const CHAR *content, int len);
Daniel Veillard16253641998-10-28 22:58:05 +0000217
Daniel Veillard260a68f1998-08-13 03:39:55 +0000218extern void xmlFreeNodeList(xmlNodePtr cur);
219extern void xmlFreeNode(xmlNodePtr cur);
Daniel Veillard16253641998-10-28 22:58:05 +0000220
221/*
222 * Namespaces
223 */
Daniel Veillard260a68f1998-08-13 03:39:55 +0000224extern xmlNsPtr xmlSearchNs(xmlDocPtr doc, xmlNodePtr node,
225 const CHAR *nameSpace);
226extern xmlNsPtr xmlSearchNsByHref(xmlDocPtr doc, xmlNodePtr node,
227 const CHAR *href);
228extern void xmlSetNs(xmlNodePtr node, xmlNsPtr ns);
Daniel Veillard260a68f1998-08-13 03:39:55 +0000229
Daniel Veillard16253641998-10-28 22:58:05 +0000230/*
231 * Changing the content.
232 */
233extern xmlAttrPtr xmlSetProp(xmlNodePtr node, const CHAR *name,
234 const CHAR *value);
235extern const CHAR *xmlGetProp(xmlNodePtr node, const CHAR *name);
236extern xmlNodePtr xmlStringGetNodeList(xmlDocPtr doc, const CHAR *value);
237extern xmlNodePtr xmlStringLenGetNodeList(xmlDocPtr doc, const CHAR *value,
238 int len);
239extern CHAR *xmlNodeListGetString(xmlDocPtr doc, xmlNodePtr list, int inLine);
240extern void xmlNodeSetContent(xmlNodePtr cur, const CHAR *content);
241extern void xmlNodeSetContentLen(xmlNodePtr cur, const CHAR *content, int len);
242extern void xmlNodeAddContent(xmlNodePtr cur, const CHAR *content);
243extern void xmlNodeAddContentLen(xmlNodePtr cur, const CHAR *content, int len);
244extern CHAR *xmlNodeGetContent(xmlNodePtr cur);
245
246/*
247 * Internal, don't use
248 */
Daniel Veillard260a68f1998-08-13 03:39:55 +0000249extern void xmlBufferWriteCHAR(const CHAR *string);
250extern void xmlBufferWriteChar(const char *string);
251
Daniel Veillard16253641998-10-28 22:58:05 +0000252/*
253 * Saving
254 */
Daniel Veillard151b1b01998-09-23 00:49:46 +0000255extern void xmlDocDumpMemory(xmlDocPtr cur, CHAR**mem, int *size);
256extern void xmlDocDump(FILE *f, xmlDocPtr doc);
257int xmlSaveFile(const char *filename, xmlDocPtr cur);
258
Daniel Veillard16253641998-10-28 22:58:05 +0000259/*
260 * Compression
261 */
Daniel Veillard15a8df41998-09-24 19:15:06 +0000262extern int xmlGetDocCompressMode (xmlDocPtr doc);
263extern void xmlSetDocCompressMode (xmlDocPtr doc, int mode);
Daniel Veillard151b1b01998-09-23 00:49:46 +0000264extern int xmlGetCompressMode(void);
265extern void xmlSetCompressMode(int mode);
Daniel Veillard260a68f1998-08-13 03:39:55 +0000266
267#ifdef __cplusplus
268}
269#endif
270
271#endif /* __XML_TREE_H__ */
272