blob: 714d4a6b42e76ac37e73a28053bffeadc552db8c [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.
91 */
92#define XML_TYPE_TEXT 1
93#define XML_TYPE_COMMENT 2
94#define XML_TYPE_ENTITY 3
95
96typedef struct xmlNode {
Daniel Veillard27864701998-10-08 03:47:24 +000097 int type; /* type number in the DTD */
Daniel Veillard260a68f1998-08-13 03:39:55 +000098 struct xmlNode *parent; /* child->parent link */
99 struct xmlNode *next; /* next sibling link */
100 struct xmlNode *childs; /* parent->childs link */
101 struct xmlAttr *properties; /* properties list */
Daniel Veillard260a68f1998-08-13 03:39:55 +0000102 const CHAR *name; /* the name of the node, or the entity */
103 xmlNs *ns; /* pointer to the associated namespace */
104 xmlNs *nsDef; /* namespace definitions on this node */
105 CHAR *content; /* the content */
Daniel Veillard27864701998-10-08 03:47:24 +0000106 void *servant; /* for Corba ! */
Daniel Veillard260a68f1998-08-13 03:39:55 +0000107} xmlNode, *xmlNodePtr;
108
109/*
110 * An XML document.
111 */
112typedef struct xmlDoc {
113 char *name; /* name/filename/URI of the document */
114 const CHAR *version; /* the XML version string */
115 const CHAR *encoding; /* encoding, if any */
Daniel Veillard15a8df41998-09-24 19:15:06 +0000116 int compression;/* level of zlib compression */
Daniel Veillard260a68f1998-08-13 03:39:55 +0000117 int standalone; /* standalone document (no external refs) */
118 struct xmlDtd *dtd; /* the document DTD if available */
119 struct xmlNs *oldNs; /* Global namespace, the old way */
120 void *entities; /* Hash table for general entities if any */
121 struct xmlNode *root; /* the document tree */
Daniel Veillard27864701998-10-08 03:47:24 +0000122 void *servant; /* for Corba ! */
Daniel Veillard260a68f1998-08-13 03:39:55 +0000123} xmlDoc, *xmlDocPtr;
124
125/*
126 * Variables.
127 */
128extern xmlNsPtr baseDTD;
129extern int oldXMLWDcompatibility;/* maintain compatibility with old WD */
130extern int xmlIndentTreeOutput; /* try to indent the tree dumps */
131
132/*
133 * Functions.
134 */
135extern xmlDtdPtr xmlNewDtd(xmlDocPtr doc, const CHAR *name,
136 const CHAR *ExternalID, const CHAR *SystemID);
137extern void xmlFreeDtd(xmlDtdPtr cur);
138extern xmlNsPtr xmlNewGlobalNs(xmlDocPtr doc, const CHAR *href, const CHAR *AS);
139extern xmlNsPtr xmlNewNs(xmlNodePtr node, const CHAR *href, const CHAR *AS);
140extern void xmlFreeNs(xmlNsPtr cur);
141extern xmlDocPtr xmlNewDoc(const CHAR *version);
142extern void xmlFreeDoc(xmlDocPtr cur);
143extern xmlAttrPtr xmlNewProp(xmlNodePtr node, const CHAR *name,
144 const CHAR *value);
145extern xmlAttrPtr xmlSetProp(xmlNodePtr node, const CHAR *name,
146 const CHAR *value);
147extern const CHAR *xmlGetProp(xmlNodePtr node, const CHAR *name);
148extern void xmlFreePropList(xmlAttrPtr cur);
149extern void xmlFreeProp(xmlAttrPtr cur);
150extern xmlNodePtr xmlNewNode(xmlNsPtr ns, const CHAR *name, CHAR *content);
151extern xmlNodePtr xmlNewText(const CHAR *content);
152extern xmlNodePtr xmlNewTextLen(const CHAR *content, int len);
153extern xmlNodePtr xmlNewComment(CHAR *content);
154extern xmlNodePtr xmlAddChild(xmlNodePtr parent, xmlNodePtr cur);
155extern xmlNodePtr xmlGetLastChild(xmlNodePtr node);
156extern int xmlNodeIsText(xmlNodePtr node);
157extern void xmlTextConcat(xmlNodePtr node, const CHAR *content, int len);
158extern void xmlFreeNodeList(xmlNodePtr cur);
159extern void xmlFreeNode(xmlNodePtr cur);
160extern void xmlNodeSetContent(xmlNodePtr cur, const CHAR *content);
161extern void xmlNodeSetContentLen(xmlNodePtr cur, const CHAR *content, int len);
162extern void xmlNodeAddContent(xmlNodePtr cur, const CHAR *content);
163extern void xmlNodeAddContentLen(xmlNodePtr cur, const CHAR *content, int len);
164extern xmlNsPtr xmlSearchNs(xmlDocPtr doc, xmlNodePtr node,
165 const CHAR *nameSpace);
166extern xmlNsPtr xmlSearchNsByHref(xmlDocPtr doc, xmlNodePtr node,
167 const CHAR *href);
168extern void xmlSetNs(xmlNodePtr node, xmlNsPtr ns);
169extern xmlNodePtr xmlNewChild(xmlNodePtr parent, xmlNsPtr ns,
170 const CHAR *name, CHAR *content);
171
Daniel Veillard260a68f1998-08-13 03:39:55 +0000172extern void xmlBufferWriteCHAR(const CHAR *string);
173extern void xmlBufferWriteChar(const char *string);
174
Daniel Veillard151b1b01998-09-23 00:49:46 +0000175extern void xmlDocDumpMemory(xmlDocPtr cur, CHAR**mem, int *size);
176extern void xmlDocDump(FILE *f, xmlDocPtr doc);
177int xmlSaveFile(const char *filename, xmlDocPtr cur);
178
Daniel Veillard15a8df41998-09-24 19:15:06 +0000179extern int xmlGetDocCompressMode (xmlDocPtr doc);
180extern void xmlSetDocCompressMode (xmlDocPtr doc, int mode);
Daniel Veillard151b1b01998-09-23 00:49:46 +0000181extern int xmlGetCompressMode(void);
182extern void xmlSetCompressMode(int mode);
Daniel Veillard260a68f1998-08-13 03:39:55 +0000183
184#ifdef __cplusplus
185}
186#endif
187
188#endif /* __XML_TREE_H__ */
189