blob: 66793bbc6c0ffbb15674c9190d145ab6ce2286ca [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/*
40 * Currently we use only 8bit chars internal representation, but
41 * the parser is not tied to that, just define UNICODE to switch to
42 * a 16 bits representation.
Daniel Veillard260a68f1998-08-13 03:39:55 +000043 */
44#ifdef UNICODE
45typedef unsigned short CHAR;
46#else
47typedef unsigned char CHAR;
48#endif
49
50/*
51 * a DTD Notation definition
52 * TODO !!!!
53 */
54
55/*
56 * a DTD Attribute definition
57 * TODO !!!!
58 */
59
60/*
61 * a DTD Element definition.
62 */
63#define XML_ELEMENT_TYPE_EMPTY 1
64#define XML_ELEMENT_TYPE_ANY 2
65#define XML_ELEMENT_TYPE_MIXED 3
66#define XML_ELEMENT_TYPE_ELEMENT 4
67
68typedef struct xmlElement {
69 const CHAR *name; /* Element name */
70 int type; /* type (too simple, to extend ...) */
71 /* TODO !!! more needed */
72} xmlElement, *xmlElementPtr;
73
74/*
75 * An XML namespace.
76 * Note that prefix == NULL is valid, it defines the default namespace
77 * within the subtree (until overriden).
78 */
79
80#define XML_GLOBAL_NAMESPACE 1 /* old style global namespace */
81#define XML_LOCAL_NAMESPACE 2 /* new style local scoping */
82
83typedef struct xmlNs {
84 struct xmlNs *next; /* next Ns link for this node */
85 int type; /* global or local */
86 const CHAR *href; /* URL for the namespace */
87 const CHAR *prefix; /* prefix for the namespace */
88} xmlNs, *xmlNsPtr;
89
90/*
91 * An XML DtD, as defined by <!DOCTYPE.
92 */
93typedef struct xmlDtd {
94 const CHAR *name; /* Name of the DTD */
95 const CHAR *ExternalID; /* External identifier for PUBLIC DTD */
96 const CHAR *SystemID; /* URI for a SYSTEM or PUBLIC DTD */
97 void *elements; /* Hash table for elements if any */
98 void *entities; /* Hash table for entities if any */
99 /* struct xmlDtd *next; * next link for this document */
100} xmlDtd, *xmlDtdPtr;
101
102/*
103 * A attribute of an XML node.
104 */
105typedef struct xmlAttr {
Daniel Veillard27fb0751998-10-17 06:47:46 +0000106#ifndef XML_WITHOUT_CORBA
107 void *_private; /* for Corba, must be first ! */
108 void *vepv; /* for Corba, must be next ! */
109#endif
Daniel Veillardccb09631998-10-27 06:21:04 +0000110 xmlElementType type; /* XML_ATTRIBUTE_NODE, must be third ! */
Daniel Veillard260a68f1998-08-13 03:39:55 +0000111 struct xmlNode *node; /* attr->node link */
112 struct xmlAttr *next; /* parent->childs link */
113 const CHAR *name; /* the name of the property */
Daniel Veillardccb09631998-10-27 06:21:04 +0000114 struct xmlNode *val; /* the value of the property */
Daniel Veillard260a68f1998-08-13 03:39:55 +0000115} xmlAttr, *xmlAttrPtr;
116
117/*
118 * A node in an XML tree.
119 */
Daniel Veillard260a68f1998-08-13 03:39:55 +0000120typedef struct xmlNode {
Daniel Veillard27fb0751998-10-17 06:47:46 +0000121#ifndef XML_WITHOUT_CORBA
122 void *_private; /* for Corba, must be first ! */
123 void *vepv; /* for Corba, must be next ! */
124#endif
Daniel Veillardccb09631998-10-27 06:21:04 +0000125 xmlElementType type; /* type number in the DTD, must be third ! */
Daniel Veillard0bef1311998-10-14 02:36:47 +0000126 struct xmlDoc *doc; /* the containing document */
Daniel Veillard260a68f1998-08-13 03:39:55 +0000127 struct xmlNode *parent; /* child->parent link */
128 struct xmlNode *next; /* next sibling link */
Daniel Veillard0bef1311998-10-14 02:36:47 +0000129 struct xmlNode *prev; /* previous sibling link */
Daniel Veillard260a68f1998-08-13 03:39:55 +0000130 struct xmlNode *childs; /* parent->childs link */
131 struct xmlAttr *properties; /* properties list */
Daniel Veillard260a68f1998-08-13 03:39:55 +0000132 const CHAR *name; /* the name of the node, or the entity */
133 xmlNs *ns; /* pointer to the associated namespace */
134 xmlNs *nsDef; /* namespace definitions on this node */
135 CHAR *content; /* the content */
136} xmlNode, *xmlNodePtr;
137
138/*
139 * An XML document.
140 */
141typedef struct xmlDoc {
Daniel Veillard27fb0751998-10-17 06:47:46 +0000142#ifndef XML_WITHOUT_CORBA
143 void *_private; /* for Corba, must be first ! */
144 void *vepv; /* for Corba, must be next ! */
145#endif
Daniel Veillardccb09631998-10-27 06:21:04 +0000146 xmlElementType type; /* XML_DOCUMENT_NODE, must be second ! */
Daniel Veillard260a68f1998-08-13 03:39:55 +0000147 char *name; /* name/filename/URI of the document */
148 const CHAR *version; /* the XML version string */
149 const CHAR *encoding; /* encoding, if any */
Daniel Veillard15a8df41998-09-24 19:15:06 +0000150 int compression;/* level of zlib compression */
Daniel Veillard260a68f1998-08-13 03:39:55 +0000151 int standalone; /* standalone document (no external refs) */
152 struct xmlDtd *dtd; /* the document DTD if available */
153 struct xmlNs *oldNs; /* Global namespace, the old way */
154 void *entities; /* Hash table for general entities if any */
155 struct xmlNode *root; /* the document tree */
156} xmlDoc, *xmlDocPtr;
157
158/*
159 * Variables.
160 */
161extern xmlNsPtr baseDTD;
162extern int oldXMLWDcompatibility;/* maintain compatibility with old WD */
163extern int xmlIndentTreeOutput; /* try to indent the tree dumps */
164
165/*
Daniel Veillard16253641998-10-28 22:58:05 +0000166 * Creating/freeing new structures
Daniel Veillard260a68f1998-08-13 03:39:55 +0000167 */
168extern xmlDtdPtr xmlNewDtd(xmlDocPtr doc, const CHAR *name,
169 const CHAR *ExternalID, const CHAR *SystemID);
170extern void xmlFreeDtd(xmlDtdPtr cur);
171extern xmlNsPtr xmlNewGlobalNs(xmlDocPtr doc, const CHAR *href, const CHAR *AS);
172extern xmlNsPtr xmlNewNs(xmlNodePtr node, const CHAR *href, const CHAR *AS);
173extern void xmlFreeNs(xmlNsPtr cur);
174extern xmlDocPtr xmlNewDoc(const CHAR *version);
175extern void xmlFreeDoc(xmlDocPtr cur);
Daniel Veillardccb09631998-10-27 06:21:04 +0000176extern xmlAttrPtr xmlNewDocProp(xmlDocPtr doc, const CHAR *name,
177 const CHAR *value);
Daniel Veillard260a68f1998-08-13 03:39:55 +0000178extern xmlAttrPtr xmlNewProp(xmlNodePtr node, const CHAR *name,
179 const CHAR *value);
Daniel Veillard260a68f1998-08-13 03:39:55 +0000180extern void xmlFreePropList(xmlAttrPtr cur);
181extern void xmlFreeProp(xmlAttrPtr cur);
Daniel Veillard16253641998-10-28 22:58:05 +0000182
183/*
184 * Creating new nodes
185 */
Daniel Veillard0bef1311998-10-14 02:36:47 +0000186extern xmlNodePtr xmlNewDocNode(xmlDocPtr doc, xmlNsPtr ns,
187 const CHAR *name, CHAR *content);
Daniel Veillardccb09631998-10-27 06:21:04 +0000188extern xmlNodePtr xmlNewNode(xmlNsPtr ns, const CHAR *name);
Daniel Veillard16253641998-10-28 22:58:05 +0000189extern xmlNodePtr xmlNewChild(xmlNodePtr parent, xmlNsPtr ns,
190 const CHAR *name, CHAR *content);
Daniel Veillard0bef1311998-10-14 02:36:47 +0000191extern xmlNodePtr xmlNewDocText(xmlDocPtr doc, const CHAR *content);
Daniel Veillard260a68f1998-08-13 03:39:55 +0000192extern xmlNodePtr xmlNewText(const CHAR *content);
Daniel Veillard0bef1311998-10-14 02:36:47 +0000193extern xmlNodePtr xmlNewDocTextLen(xmlDocPtr doc, const CHAR *content, int len);
Daniel Veillard260a68f1998-08-13 03:39:55 +0000194extern xmlNodePtr xmlNewTextLen(const CHAR *content, int len);
Daniel Veillard0bef1311998-10-14 02:36:47 +0000195extern xmlNodePtr xmlNewDocComment(xmlDocPtr doc, CHAR *content);
Daniel Veillard260a68f1998-08-13 03:39:55 +0000196extern xmlNodePtr xmlNewComment(CHAR *content);
Daniel Veillardccb09631998-10-27 06:21:04 +0000197extern xmlNodePtr xmlNewReference(xmlDocPtr doc, const CHAR *name);
Daniel Veillard16253641998-10-28 22:58:05 +0000198
199/*
200 * Navigating
201 */
Daniel Veillard260a68f1998-08-13 03:39:55 +0000202extern xmlNodePtr xmlGetLastChild(xmlNodePtr node);
203extern int xmlNodeIsText(xmlNodePtr node);
Daniel Veillard16253641998-10-28 22:58:05 +0000204
205/*
206 * Changing the structure
207 */
208extern xmlNodePtr xmlAddChild(xmlNodePtr parent, xmlNodePtr cur);
209extern void xmlUnlinkNode(xmlNodePtr cur);
210
211extern xmlNodePtr xmlTextMerge(xmlNodePtr first, xmlNodePtr second);
Daniel Veillard260a68f1998-08-13 03:39:55 +0000212extern void xmlTextConcat(xmlNodePtr node, const CHAR *content, int len);
Daniel Veillard16253641998-10-28 22:58:05 +0000213
Daniel Veillard260a68f1998-08-13 03:39:55 +0000214extern void xmlFreeNodeList(xmlNodePtr cur);
215extern void xmlFreeNode(xmlNodePtr cur);
Daniel Veillard16253641998-10-28 22:58:05 +0000216
217/*
218 * Namespaces
219 */
Daniel Veillard260a68f1998-08-13 03:39:55 +0000220extern xmlNsPtr xmlSearchNs(xmlDocPtr doc, xmlNodePtr node,
221 const CHAR *nameSpace);
222extern xmlNsPtr xmlSearchNsByHref(xmlDocPtr doc, xmlNodePtr node,
223 const CHAR *href);
224extern void xmlSetNs(xmlNodePtr node, xmlNsPtr ns);
Daniel Veillard260a68f1998-08-13 03:39:55 +0000225
Daniel Veillard16253641998-10-28 22:58:05 +0000226/*
227 * Changing the content.
228 */
229extern xmlAttrPtr xmlSetProp(xmlNodePtr node, const CHAR *name,
230 const CHAR *value);
231extern const CHAR *xmlGetProp(xmlNodePtr node, const CHAR *name);
232extern xmlNodePtr xmlStringGetNodeList(xmlDocPtr doc, const CHAR *value);
233extern xmlNodePtr xmlStringLenGetNodeList(xmlDocPtr doc, const CHAR *value,
234 int len);
235extern CHAR *xmlNodeListGetString(xmlDocPtr doc, xmlNodePtr list, int inLine);
236extern void xmlNodeSetContent(xmlNodePtr cur, const CHAR *content);
237extern void xmlNodeSetContentLen(xmlNodePtr cur, const CHAR *content, int len);
238extern void xmlNodeAddContent(xmlNodePtr cur, const CHAR *content);
239extern void xmlNodeAddContentLen(xmlNodePtr cur, const CHAR *content, int len);
240extern CHAR *xmlNodeGetContent(xmlNodePtr cur);
241
242/*
243 * Internal, don't use
244 */
Daniel Veillard260a68f1998-08-13 03:39:55 +0000245extern void xmlBufferWriteCHAR(const CHAR *string);
246extern void xmlBufferWriteChar(const char *string);
247
Daniel Veillard16253641998-10-28 22:58:05 +0000248/*
249 * Saving
250 */
Daniel Veillard151b1b01998-09-23 00:49:46 +0000251extern void xmlDocDumpMemory(xmlDocPtr cur, CHAR**mem, int *size);
252extern void xmlDocDump(FILE *f, xmlDocPtr doc);
253int xmlSaveFile(const char *filename, xmlDocPtr cur);
254
Daniel Veillard16253641998-10-28 22:58:05 +0000255/*
256 * Compression
257 */
Daniel Veillard15a8df41998-09-24 19:15:06 +0000258extern int xmlGetDocCompressMode (xmlDocPtr doc);
259extern void xmlSetDocCompressMode (xmlDocPtr doc, int mode);
Daniel Veillard151b1b01998-09-23 00:49:46 +0000260extern int xmlGetCompressMode(void);
261extern void xmlSetCompressMode(int mode);
Daniel Veillard260a68f1998-08-13 03:39:55 +0000262
263#ifdef __cplusplus
264}
265#endif
266
267#endif /* __XML_TREE_H__ */
268