blob: 7a48a9bd6b876d1506cc8a06c1f90d0c52e8cdce [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 */
115 int standalone; /* standalone document (no external refs) */
116 struct xmlDtd *dtd; /* the document DTD if available */
117 struct xmlNs *oldNs; /* Global namespace, the old way */
118 void *entities; /* Hash table for general entities if any */
119 struct xmlNode *root; /* the document tree */
120} xmlDoc, *xmlDocPtr;
121
122/*
123 * Variables.
124 */
125extern xmlNsPtr baseDTD;
126extern int oldXMLWDcompatibility;/* maintain compatibility with old WD */
127extern int xmlIndentTreeOutput; /* try to indent the tree dumps */
128
129/*
130 * Functions.
131 */
132extern xmlDtdPtr xmlNewDtd(xmlDocPtr doc, const CHAR *name,
133 const CHAR *ExternalID, const CHAR *SystemID);
134extern void xmlFreeDtd(xmlDtdPtr cur);
135extern xmlNsPtr xmlNewGlobalNs(xmlDocPtr doc, const CHAR *href, const CHAR *AS);
136extern xmlNsPtr xmlNewNs(xmlNodePtr node, const CHAR *href, const CHAR *AS);
137extern void xmlFreeNs(xmlNsPtr cur);
138extern xmlDocPtr xmlNewDoc(const CHAR *version);
139extern void xmlFreeDoc(xmlDocPtr cur);
140extern xmlAttrPtr xmlNewProp(xmlNodePtr node, const CHAR *name,
141 const CHAR *value);
142extern xmlAttrPtr xmlSetProp(xmlNodePtr node, const CHAR *name,
143 const CHAR *value);
144extern const CHAR *xmlGetProp(xmlNodePtr node, const CHAR *name);
145extern void xmlFreePropList(xmlAttrPtr cur);
146extern void xmlFreeProp(xmlAttrPtr cur);
147extern xmlNodePtr xmlNewNode(xmlNsPtr ns, const CHAR *name, CHAR *content);
148extern xmlNodePtr xmlNewText(const CHAR *content);
149extern xmlNodePtr xmlNewTextLen(const CHAR *content, int len);
150extern xmlNodePtr xmlNewComment(CHAR *content);
151extern xmlNodePtr xmlAddChild(xmlNodePtr parent, xmlNodePtr cur);
152extern xmlNodePtr xmlGetLastChild(xmlNodePtr node);
153extern int xmlNodeIsText(xmlNodePtr node);
154extern void xmlTextConcat(xmlNodePtr node, const CHAR *content, int len);
155extern void xmlFreeNodeList(xmlNodePtr cur);
156extern void xmlFreeNode(xmlNodePtr cur);
157extern void xmlNodeSetContent(xmlNodePtr cur, const CHAR *content);
158extern void xmlNodeSetContentLen(xmlNodePtr cur, const CHAR *content, int len);
159extern void xmlNodeAddContent(xmlNodePtr cur, const CHAR *content);
160extern void xmlNodeAddContentLen(xmlNodePtr cur, const CHAR *content, int len);
161extern xmlNsPtr xmlSearchNs(xmlDocPtr doc, xmlNodePtr node,
162 const CHAR *nameSpace);
163extern xmlNsPtr xmlSearchNsByHref(xmlDocPtr doc, xmlNodePtr node,
164 const CHAR *href);
165extern void xmlSetNs(xmlNodePtr node, xmlNsPtr ns);
166extern xmlNodePtr xmlNewChild(xmlNodePtr parent, xmlNsPtr ns,
167 const CHAR *name, CHAR *content);
168
169extern void xmlDocDumpMemory(xmlDocPtr cur, CHAR**mem, int *size);
170extern void xmlDocDump(FILE *f, xmlDocPtr doc);
171extern void xmlBufferWriteCHAR(const CHAR *string);
172extern void xmlBufferWriteChar(const char *string);
173
174
175#ifdef __cplusplus
176}
177#endif
178
179#endif /* __XML_TREE_H__ */
180