blob: 3921f7eae09de17181f2a6d5ee7dbcb9f40285af [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 */
Daniel Veillardbe36afe1998-11-27 06:39:50 +0000158 void *entities; /* Hash table for general entities if any */
Daniel Veillard260a68f1998-08-13 03:39:55 +0000159 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 Veillardbe36afe1998-11-27 06:39:50 +0000186extern xmlAttrPtr xmlCopyProp(xmlAttrPtr cur);
187extern xmlAttrPtr xmlCopyPropList(xmlAttrPtr cur);
188extern xmlDtdPtr xmlCopyDtd(xmlDtdPtr dtd);
189extern xmlDocPtr xmlCopyDoc(xmlDocPtr doc, int recursive);
Daniel Veillard16253641998-10-28 22:58:05 +0000190
191/*
192 * Creating new nodes
193 */
Daniel Veillard0bef1311998-10-14 02:36:47 +0000194extern xmlNodePtr xmlNewDocNode(xmlDocPtr doc, xmlNsPtr ns,
195 const CHAR *name, CHAR *content);
Daniel Veillardccb09631998-10-27 06:21:04 +0000196extern xmlNodePtr xmlNewNode(xmlNsPtr ns, const CHAR *name);
Daniel Veillard16253641998-10-28 22:58:05 +0000197extern xmlNodePtr xmlNewChild(xmlNodePtr parent, xmlNsPtr ns,
198 const CHAR *name, CHAR *content);
Daniel Veillard0bef1311998-10-14 02:36:47 +0000199extern xmlNodePtr xmlNewDocText(xmlDocPtr doc, const CHAR *content);
Daniel Veillard260a68f1998-08-13 03:39:55 +0000200extern xmlNodePtr xmlNewText(const CHAR *content);
Daniel Veillard0bef1311998-10-14 02:36:47 +0000201extern xmlNodePtr xmlNewDocTextLen(xmlDocPtr doc, const CHAR *content, int len);
Daniel Veillard260a68f1998-08-13 03:39:55 +0000202extern xmlNodePtr xmlNewTextLen(const CHAR *content, int len);
Daniel Veillard0bef1311998-10-14 02:36:47 +0000203extern xmlNodePtr xmlNewDocComment(xmlDocPtr doc, CHAR *content);
Daniel Veillard260a68f1998-08-13 03:39:55 +0000204extern xmlNodePtr xmlNewComment(CHAR *content);
Daniel Veillardccb09631998-10-27 06:21:04 +0000205extern xmlNodePtr xmlNewReference(xmlDocPtr doc, const CHAR *name);
Daniel Veillardbe36afe1998-11-27 06:39:50 +0000206extern xmlNodePtr xmlCopyNode(xmlNodePtr node, int recursive);
207extern xmlNodePtr xmlCopyNodeList(xmlNodePtr node);
Daniel Veillard16253641998-10-28 22:58:05 +0000208
209/*
210 * Navigating
211 */
Daniel Veillard260a68f1998-08-13 03:39:55 +0000212extern xmlNodePtr xmlGetLastChild(xmlNodePtr node);
213extern int xmlNodeIsText(xmlNodePtr node);
Daniel Veillard16253641998-10-28 22:58:05 +0000214
215/*
216 * Changing the structure
217 */
218extern xmlNodePtr xmlAddChild(xmlNodePtr parent, xmlNodePtr cur);
219extern void xmlUnlinkNode(xmlNodePtr cur);
220
221extern xmlNodePtr xmlTextMerge(xmlNodePtr first, xmlNodePtr second);
Daniel Veillard260a68f1998-08-13 03:39:55 +0000222extern void xmlTextConcat(xmlNodePtr node, const CHAR *content, int len);
Daniel Veillard16253641998-10-28 22:58:05 +0000223
Daniel Veillard260a68f1998-08-13 03:39:55 +0000224extern void xmlFreeNodeList(xmlNodePtr cur);
225extern void xmlFreeNode(xmlNodePtr cur);
Daniel Veillard16253641998-10-28 22:58:05 +0000226
227/*
228 * Namespaces
229 */
Daniel Veillard260a68f1998-08-13 03:39:55 +0000230extern xmlNsPtr xmlSearchNs(xmlDocPtr doc, xmlNodePtr node,
231 const CHAR *nameSpace);
232extern xmlNsPtr xmlSearchNsByHref(xmlDocPtr doc, xmlNodePtr node,
233 const CHAR *href);
234extern void xmlSetNs(xmlNodePtr node, xmlNsPtr ns);
Daniel Veillardbe36afe1998-11-27 06:39:50 +0000235extern xmlNsPtr xmlCopyNamespace(xmlNsPtr cur);
236extern xmlNsPtr xmlCopyNamespaceList(xmlNsPtr cur);
Daniel Veillard260a68f1998-08-13 03:39:55 +0000237
Daniel Veillard16253641998-10-28 22:58:05 +0000238/*
239 * Changing the content.
240 */
241extern xmlAttrPtr xmlSetProp(xmlNodePtr node, const CHAR *name,
242 const CHAR *value);
243extern const CHAR *xmlGetProp(xmlNodePtr node, const CHAR *name);
244extern xmlNodePtr xmlStringGetNodeList(xmlDocPtr doc, const CHAR *value);
245extern xmlNodePtr xmlStringLenGetNodeList(xmlDocPtr doc, const CHAR *value,
246 int len);
247extern CHAR *xmlNodeListGetString(xmlDocPtr doc, xmlNodePtr list, int inLine);
248extern void xmlNodeSetContent(xmlNodePtr cur, const CHAR *content);
249extern void xmlNodeSetContentLen(xmlNodePtr cur, const CHAR *content, int len);
250extern void xmlNodeAddContent(xmlNodePtr cur, const CHAR *content);
251extern void xmlNodeAddContentLen(xmlNodePtr cur, const CHAR *content, int len);
252extern CHAR *xmlNodeGetContent(xmlNodePtr cur);
253
254/*
255 * Internal, don't use
256 */
Daniel Veillard260a68f1998-08-13 03:39:55 +0000257extern void xmlBufferWriteCHAR(const CHAR *string);
258extern void xmlBufferWriteChar(const char *string);
259
Daniel Veillard16253641998-10-28 22:58:05 +0000260/*
261 * Saving
262 */
Daniel Veillard151b1b01998-09-23 00:49:46 +0000263extern void xmlDocDumpMemory(xmlDocPtr cur, CHAR**mem, int *size);
264extern void xmlDocDump(FILE *f, xmlDocPtr doc);
265int xmlSaveFile(const char *filename, xmlDocPtr cur);
266
Daniel Veillard16253641998-10-28 22:58:05 +0000267/*
268 * Compression
269 */
Daniel Veillard15a8df41998-09-24 19:15:06 +0000270extern int xmlGetDocCompressMode (xmlDocPtr doc);
271extern void xmlSetDocCompressMode (xmlDocPtr doc, int mode);
Daniel Veillard151b1b01998-09-23 00:49:46 +0000272extern int xmlGetCompressMode(void);
273extern void xmlSetCompressMode(int mode);
Daniel Veillard260a68f1998-08-13 03:39:55 +0000274
275#ifdef __cplusplus
276}
277#endif
278
279#endif /* __XML_TREE_H__ */
280