blob: b79d4b92af7bdd77da6c80aba77bea27b0b6360d [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 {
97 struct xmlNode *parent; /* child->parent link */
98 struct xmlNode *next; /* next sibling link */
99 struct xmlNode *childs; /* parent->childs link */
100 struct xmlAttr *properties; /* properties list */
101 int type; /* type number in the DTD */
102 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 */
106} xmlNode, *xmlNodePtr;
107
108/*
109 * An XML document.
110 */
111typedef struct xmlDoc {
112 char *name; /* name/filename/URI of the document */
113 const CHAR *version; /* the XML version string */
114 const CHAR *encoding; /* encoding, if any */
Daniel Veillard15a8df41998-09-24 19:15:06 +0000115 int compression;/* level of zlib compression */
Daniel Veillard260a68f1998-08-13 03:39:55 +0000116 int standalone; /* standalone document (no external refs) */
117 struct xmlDtd *dtd; /* the document DTD if available */
118 struct xmlNs *oldNs; /* Global namespace, the old way */
119 void *entities; /* Hash table for general entities if any */
120 struct xmlNode *root; /* the document tree */
121} xmlDoc, *xmlDocPtr;
122
123/*
124 * Variables.
125 */
126extern xmlNsPtr baseDTD;
127extern int oldXMLWDcompatibility;/* maintain compatibility with old WD */
128extern int xmlIndentTreeOutput; /* try to indent the tree dumps */
129
130/*
131 * Functions.
132 */
133extern xmlDtdPtr xmlNewDtd(xmlDocPtr doc, const CHAR *name,
134 const CHAR *ExternalID, const CHAR *SystemID);
135extern void xmlFreeDtd(xmlDtdPtr cur);
136extern xmlNsPtr xmlNewGlobalNs(xmlDocPtr doc, const CHAR *href, const CHAR *AS);
137extern xmlNsPtr xmlNewNs(xmlNodePtr node, const CHAR *href, const CHAR *AS);
138extern void xmlFreeNs(xmlNsPtr cur);
139extern xmlDocPtr xmlNewDoc(const CHAR *version);
140extern void xmlFreeDoc(xmlDocPtr cur);
141extern xmlAttrPtr xmlNewProp(xmlNodePtr node, const CHAR *name,
142 const CHAR *value);
143extern xmlAttrPtr xmlSetProp(xmlNodePtr node, const CHAR *name,
144 const CHAR *value);
145extern const CHAR *xmlGetProp(xmlNodePtr node, const CHAR *name);
146extern void xmlFreePropList(xmlAttrPtr cur);
147extern void xmlFreeProp(xmlAttrPtr cur);
148extern xmlNodePtr xmlNewNode(xmlNsPtr ns, const CHAR *name, CHAR *content);
149extern xmlNodePtr xmlNewText(const CHAR *content);
150extern xmlNodePtr xmlNewTextLen(const CHAR *content, int len);
151extern xmlNodePtr xmlNewComment(CHAR *content);
152extern xmlNodePtr xmlAddChild(xmlNodePtr parent, xmlNodePtr cur);
153extern xmlNodePtr xmlGetLastChild(xmlNodePtr node);
154extern int xmlNodeIsText(xmlNodePtr node);
155extern void xmlTextConcat(xmlNodePtr node, const CHAR *content, int len);
156extern void xmlFreeNodeList(xmlNodePtr cur);
157extern void xmlFreeNode(xmlNodePtr cur);
158extern void xmlNodeSetContent(xmlNodePtr cur, const CHAR *content);
159extern void xmlNodeSetContentLen(xmlNodePtr cur, const CHAR *content, int len);
160extern void xmlNodeAddContent(xmlNodePtr cur, const CHAR *content);
161extern void xmlNodeAddContentLen(xmlNodePtr cur, const CHAR *content, int len);
162extern xmlNsPtr xmlSearchNs(xmlDocPtr doc, xmlNodePtr node,
163 const CHAR *nameSpace);
164extern xmlNsPtr xmlSearchNsByHref(xmlDocPtr doc, xmlNodePtr node,
165 const CHAR *href);
166extern void xmlSetNs(xmlNodePtr node, xmlNsPtr ns);
167extern xmlNodePtr xmlNewChild(xmlNodePtr parent, xmlNsPtr ns,
168 const CHAR *name, CHAR *content);
169
Daniel Veillard260a68f1998-08-13 03:39:55 +0000170extern void xmlBufferWriteCHAR(const CHAR *string);
171extern void xmlBufferWriteChar(const char *string);
172
Daniel Veillard151b1b01998-09-23 00:49:46 +0000173extern void xmlDocDumpMemory(xmlDocPtr cur, CHAR**mem, int *size);
174extern void xmlDocDump(FILE *f, xmlDocPtr doc);
175int xmlSaveFile(const char *filename, xmlDocPtr cur);
176
Daniel Veillard15a8df41998-09-24 19:15:06 +0000177extern int xmlGetDocCompressMode (xmlDocPtr doc);
178extern void xmlSetDocCompressMode (xmlDocPtr doc, int mode);
Daniel Veillard151b1b01998-09-23 00:49:46 +0000179extern int xmlGetCompressMode(void);
180extern void xmlSetCompressMode(int mode);
Daniel Veillard260a68f1998-08-13 03:39:55 +0000181
182#ifdef __cplusplus
183}
184#endif
185
186#endif /* __XML_TREE_H__ */
187