blob: a4a808d8a37dae170878f71ba09b583b0ab0ae3b [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 {
83 struct xmlNode *node; /* attr->node link */
84 struct xmlAttr *next; /* parent->childs link */
85 const CHAR *name; /* the name of the property */
86 const CHAR *value; /* the value of the property */
87} xmlAttr, *xmlAttrPtr;
88
89/*
90 * A node in an XML tree.
Daniel Veillard0bef1311998-10-14 02:36:47 +000091 * NOTE: This is synchronized with DOM Level1 values
92 * See http://www.w3.org/TR/REC-DOM-Level-1/
Daniel Veillard260a68f1998-08-13 03:39:55 +000093 */
Daniel Veillard0bef1311998-10-14 02:36:47 +000094#define XML_ELEMENT_NODE 1
95#define XML_ATTRIBUTE_NODE 2
96#define XML_TEXT_NODE 3
97#define XML_CDATA_SECTION_NODE 4
98#define XML_ENTITY_REF_NODE 5
99#define XML_ENTITY_NODE 6
100#define XML_PI_NODE 7
101#define XML_COMMENT_NODE 8
102#define XML_DOCUMENT_NODE 9
103#define XML_DOCUMENT_TYPE_NODE 10
104#define XML_DOCUMENT_FRAG_NODE 11
105#define XML_NOTATION_NODE 12
Daniel Veillard260a68f1998-08-13 03:39:55 +0000106
107typedef struct xmlNode {
Daniel Veillard27864701998-10-08 03:47:24 +0000108 int type; /* type number in the DTD */
Daniel Veillard0bef1311998-10-14 02:36:47 +0000109 struct xmlDoc *doc; /* the containing document */
Daniel Veillard260a68f1998-08-13 03:39:55 +0000110 struct xmlNode *parent; /* child->parent link */
111 struct xmlNode *next; /* next sibling link */
Daniel Veillard0bef1311998-10-14 02:36:47 +0000112 struct xmlNode *prev; /* previous sibling link */
Daniel Veillard260a68f1998-08-13 03:39:55 +0000113 struct xmlNode *childs; /* parent->childs link */
114 struct xmlAttr *properties; /* properties list */
Daniel Veillard260a68f1998-08-13 03:39:55 +0000115 const CHAR *name; /* the name of the node, or the entity */
116 xmlNs *ns; /* pointer to the associated namespace */
117 xmlNs *nsDef; /* namespace definitions on this node */
118 CHAR *content; /* the content */
Daniel Veillard27864701998-10-08 03:47:24 +0000119 void *servant; /* for Corba ! */
Daniel Veillard260a68f1998-08-13 03:39:55 +0000120} xmlNode, *xmlNodePtr;
121
122/*
123 * An XML document.
124 */
125typedef struct xmlDoc {
126 char *name; /* name/filename/URI of the document */
127 const CHAR *version; /* the XML version string */
128 const CHAR *encoding; /* encoding, if any */
Daniel Veillard15a8df41998-09-24 19:15:06 +0000129 int compression;/* level of zlib compression */
Daniel Veillard260a68f1998-08-13 03:39:55 +0000130 int standalone; /* standalone document (no external refs) */
131 struct xmlDtd *dtd; /* the document DTD if available */
132 struct xmlNs *oldNs; /* Global namespace, the old way */
133 void *entities; /* Hash table for general entities if any */
134 struct xmlNode *root; /* the document tree */
Daniel Veillard27864701998-10-08 03:47:24 +0000135 void *servant; /* for Corba ! */
Daniel Veillard260a68f1998-08-13 03:39:55 +0000136} xmlDoc, *xmlDocPtr;
137
138/*
139 * Variables.
140 */
141extern xmlNsPtr baseDTD;
142extern int oldXMLWDcompatibility;/* maintain compatibility with old WD */
143extern int xmlIndentTreeOutput; /* try to indent the tree dumps */
144
145/*
146 * Functions.
147 */
148extern xmlDtdPtr xmlNewDtd(xmlDocPtr doc, const CHAR *name,
149 const CHAR *ExternalID, const CHAR *SystemID);
150extern void xmlFreeDtd(xmlDtdPtr cur);
151extern xmlNsPtr xmlNewGlobalNs(xmlDocPtr doc, const CHAR *href, const CHAR *AS);
152extern xmlNsPtr xmlNewNs(xmlNodePtr node, const CHAR *href, const CHAR *AS);
153extern void xmlFreeNs(xmlNsPtr cur);
154extern xmlDocPtr xmlNewDoc(const CHAR *version);
155extern void xmlFreeDoc(xmlDocPtr cur);
156extern xmlAttrPtr xmlNewProp(xmlNodePtr node, const CHAR *name,
157 const CHAR *value);
158extern xmlAttrPtr xmlSetProp(xmlNodePtr node, const CHAR *name,
159 const CHAR *value);
160extern const CHAR *xmlGetProp(xmlNodePtr node, const CHAR *name);
161extern void xmlFreePropList(xmlAttrPtr cur);
162extern void xmlFreeProp(xmlAttrPtr cur);
Daniel Veillard0bef1311998-10-14 02:36:47 +0000163extern xmlNodePtr xmlNewDocNode(xmlDocPtr doc, xmlNsPtr ns,
164 const CHAR *name, CHAR *content);
Daniel Veillard260a68f1998-08-13 03:39:55 +0000165extern xmlNodePtr xmlNewNode(xmlNsPtr ns, const CHAR *name, CHAR *content);
Daniel Veillard0bef1311998-10-14 02:36:47 +0000166extern xmlNodePtr xmlNewDocText(xmlDocPtr doc, const CHAR *content);
Daniel Veillard260a68f1998-08-13 03:39:55 +0000167extern xmlNodePtr xmlNewText(const CHAR *content);
Daniel Veillard0bef1311998-10-14 02:36:47 +0000168extern xmlNodePtr xmlNewDocTextLen(xmlDocPtr doc, const CHAR *content, int len);
Daniel Veillard260a68f1998-08-13 03:39:55 +0000169extern xmlNodePtr xmlNewTextLen(const CHAR *content, int len);
Daniel Veillard0bef1311998-10-14 02:36:47 +0000170extern xmlNodePtr xmlNewDocComment(xmlDocPtr doc, CHAR *content);
Daniel Veillard260a68f1998-08-13 03:39:55 +0000171extern xmlNodePtr xmlNewComment(CHAR *content);
172extern xmlNodePtr xmlAddChild(xmlNodePtr parent, xmlNodePtr cur);
173extern xmlNodePtr xmlGetLastChild(xmlNodePtr node);
174extern int xmlNodeIsText(xmlNodePtr node);
175extern void xmlTextConcat(xmlNodePtr node, const CHAR *content, int len);
176extern void xmlFreeNodeList(xmlNodePtr cur);
177extern void xmlFreeNode(xmlNodePtr cur);
178extern void xmlNodeSetContent(xmlNodePtr cur, const CHAR *content);
179extern void xmlNodeSetContentLen(xmlNodePtr cur, const CHAR *content, int len);
180extern void xmlNodeAddContent(xmlNodePtr cur, const CHAR *content);
181extern void xmlNodeAddContentLen(xmlNodePtr cur, const CHAR *content, int len);
182extern xmlNsPtr xmlSearchNs(xmlDocPtr doc, xmlNodePtr node,
183 const CHAR *nameSpace);
184extern xmlNsPtr xmlSearchNsByHref(xmlDocPtr doc, xmlNodePtr node,
185 const CHAR *href);
186extern void xmlSetNs(xmlNodePtr node, xmlNsPtr ns);
187extern xmlNodePtr xmlNewChild(xmlNodePtr parent, xmlNsPtr ns,
188 const CHAR *name, CHAR *content);
Daniel Veillard0bef1311998-10-14 02:36:47 +0000189extern xmlNodePtr xmlNewChild(xmlNodePtr parent, xmlNsPtr ns,
190 const CHAR *name, CHAR *content);
Daniel Veillard260a68f1998-08-13 03:39:55 +0000191
Daniel Veillard260a68f1998-08-13 03:39:55 +0000192extern void xmlBufferWriteCHAR(const CHAR *string);
193extern void xmlBufferWriteChar(const char *string);
194
Daniel Veillard151b1b01998-09-23 00:49:46 +0000195extern void xmlDocDumpMemory(xmlDocPtr cur, CHAR**mem, int *size);
196extern void xmlDocDump(FILE *f, xmlDocPtr doc);
197int xmlSaveFile(const char *filename, xmlDocPtr cur);
198
Daniel Veillard15a8df41998-09-24 19:15:06 +0000199extern int xmlGetDocCompressMode (xmlDocPtr doc);
200extern void xmlSetDocCompressMode (xmlDocPtr doc, int mode);
Daniel Veillard151b1b01998-09-23 00:49:46 +0000201extern int xmlGetCompressMode(void);
202extern void xmlSetCompressMode(int mode);
Daniel Veillard260a68f1998-08-13 03:39:55 +0000203
204#ifdef __cplusplus
205}
206#endif
207
208#endif /* __XML_TREE_H__ */
209