blob: 2ebe2cdf22ff4c1d9b1d7c98729f300fab393bd7 [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/*
166 * Functions.
167 */
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);
180extern xmlAttrPtr xmlSetProp(xmlNodePtr node, const CHAR *name,
181 const CHAR *value);
182extern const CHAR *xmlGetProp(xmlNodePtr node, const CHAR *name);
Daniel Veillardccb09631998-10-27 06:21:04 +0000183extern xmlNodePtr xmlStringGetNodeList(xmlDocPtr doc, const CHAR *value);
184extern CHAR *xmlNodeListGetString(xmlDocPtr doc, xmlNodePtr list, int inLine);
Daniel Veillard260a68f1998-08-13 03:39:55 +0000185extern void xmlFreePropList(xmlAttrPtr cur);
186extern void xmlFreeProp(xmlAttrPtr cur);
Daniel Veillard0bef1311998-10-14 02:36:47 +0000187extern xmlNodePtr xmlNewDocNode(xmlDocPtr doc, xmlNsPtr ns,
188 const CHAR *name, CHAR *content);
Daniel Veillardccb09631998-10-27 06:21:04 +0000189extern xmlNodePtr xmlNewNode(xmlNsPtr ns, const CHAR *name);
Daniel Veillard0bef1311998-10-14 02:36:47 +0000190extern xmlNodePtr xmlNewDocText(xmlDocPtr doc, const CHAR *content);
Daniel Veillard260a68f1998-08-13 03:39:55 +0000191extern xmlNodePtr xmlNewText(const CHAR *content);
Daniel Veillard0bef1311998-10-14 02:36:47 +0000192extern xmlNodePtr xmlNewDocTextLen(xmlDocPtr doc, const CHAR *content, int len);
Daniel Veillard260a68f1998-08-13 03:39:55 +0000193extern xmlNodePtr xmlNewTextLen(const CHAR *content, int len);
Daniel Veillard0bef1311998-10-14 02:36:47 +0000194extern xmlNodePtr xmlNewDocComment(xmlDocPtr doc, CHAR *content);
Daniel Veillard260a68f1998-08-13 03:39:55 +0000195extern xmlNodePtr xmlNewComment(CHAR *content);
Daniel Veillardccb09631998-10-27 06:21:04 +0000196extern xmlNodePtr xmlNewReference(xmlDocPtr doc, const CHAR *name);
Daniel Veillard260a68f1998-08-13 03:39:55 +0000197extern xmlNodePtr xmlAddChild(xmlNodePtr parent, xmlNodePtr cur);
198extern xmlNodePtr xmlGetLastChild(xmlNodePtr node);
199extern int xmlNodeIsText(xmlNodePtr node);
200extern void xmlTextConcat(xmlNodePtr node, const CHAR *content, int len);
201extern void xmlFreeNodeList(xmlNodePtr cur);
202extern void xmlFreeNode(xmlNodePtr cur);
203extern void xmlNodeSetContent(xmlNodePtr cur, const CHAR *content);
204extern void xmlNodeSetContentLen(xmlNodePtr cur, const CHAR *content, int len);
205extern void xmlNodeAddContent(xmlNodePtr cur, const CHAR *content);
206extern void xmlNodeAddContentLen(xmlNodePtr cur, const CHAR *content, int len);
207extern xmlNsPtr xmlSearchNs(xmlDocPtr doc, xmlNodePtr node,
208 const CHAR *nameSpace);
209extern xmlNsPtr xmlSearchNsByHref(xmlDocPtr doc, xmlNodePtr node,
210 const CHAR *href);
211extern void xmlSetNs(xmlNodePtr node, xmlNsPtr ns);
212extern xmlNodePtr xmlNewChild(xmlNodePtr parent, xmlNsPtr ns,
213 const CHAR *name, CHAR *content);
Daniel Veillard0bef1311998-10-14 02:36:47 +0000214extern xmlNodePtr xmlNewChild(xmlNodePtr parent, xmlNsPtr ns,
215 const CHAR *name, CHAR *content);
Daniel Veillard260a68f1998-08-13 03:39:55 +0000216
Daniel Veillard260a68f1998-08-13 03:39:55 +0000217extern void xmlBufferWriteCHAR(const CHAR *string);
218extern void xmlBufferWriteChar(const char *string);
219
Daniel Veillard151b1b01998-09-23 00:49:46 +0000220extern void xmlDocDumpMemory(xmlDocPtr cur, CHAR**mem, int *size);
221extern void xmlDocDump(FILE *f, xmlDocPtr doc);
222int xmlSaveFile(const char *filename, xmlDocPtr cur);
223
Daniel Veillard15a8df41998-09-24 19:15:06 +0000224extern int xmlGetDocCompressMode (xmlDocPtr doc);
225extern void xmlSetDocCompressMode (xmlDocPtr doc, int mode);
Daniel Veillard151b1b01998-09-23 00:49:46 +0000226extern int xmlGetCompressMode(void);
227extern void xmlSetCompressMode(int mode);
Daniel Veillard260a68f1998-08-13 03:39:55 +0000228
229#ifdef __cplusplus
230}
231#endif
232
233#endif /* __XML_TREE_H__ */
234