Daniel Veillard | 260a68f | 1998-08-13 03:39:55 +0000 | [diff] [blame] | 1 | /* |
| 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 |
| 15 | extern "C" { |
| 16 | #endif |
| 17 | |
| 18 | /* |
Daniel Veillard | ccb0963 | 1998-10-27 06:21:04 +0000 | [diff] [blame] | 19 | * 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 | */ |
| 24 | typedef 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 Veillard | 260a68f | 1998-08-13 03:39:55 +0000 | [diff] [blame] | 43 | */ |
| 44 | #ifdef UNICODE |
| 45 | typedef unsigned short CHAR; |
| 46 | #else |
| 47 | typedef 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 | |
| 68 | typedef 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 | |
| 83 | typedef 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 | */ |
| 93 | typedef 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 | */ |
| 105 | typedef struct xmlAttr { |
Daniel Veillard | 27fb075 | 1998-10-17 06:47:46 +0000 | [diff] [blame] | 106 | #ifndef XML_WITHOUT_CORBA |
| 107 | void *_private; /* for Corba, must be first ! */ |
| 108 | void *vepv; /* for Corba, must be next ! */ |
| 109 | #endif |
Daniel Veillard | ccb0963 | 1998-10-27 06:21:04 +0000 | [diff] [blame] | 110 | xmlElementType type; /* XML_ATTRIBUTE_NODE, must be third ! */ |
Daniel Veillard | 260a68f | 1998-08-13 03:39:55 +0000 | [diff] [blame] | 111 | struct xmlNode *node; /* attr->node link */ |
| 112 | struct xmlAttr *next; /* parent->childs link */ |
| 113 | const CHAR *name; /* the name of the property */ |
Daniel Veillard | ccb0963 | 1998-10-27 06:21:04 +0000 | [diff] [blame] | 114 | struct xmlNode *val; /* the value of the property */ |
Daniel Veillard | 260a68f | 1998-08-13 03:39:55 +0000 | [diff] [blame] | 115 | } xmlAttr, *xmlAttrPtr; |
| 116 | |
| 117 | /* |
| 118 | * A node in an XML tree. |
| 119 | */ |
Daniel Veillard | 260a68f | 1998-08-13 03:39:55 +0000 | [diff] [blame] | 120 | typedef struct xmlNode { |
Daniel Veillard | 27fb075 | 1998-10-17 06:47:46 +0000 | [diff] [blame] | 121 | #ifndef XML_WITHOUT_CORBA |
| 122 | void *_private; /* for Corba, must be first ! */ |
| 123 | void *vepv; /* for Corba, must be next ! */ |
| 124 | #endif |
Daniel Veillard | ccb0963 | 1998-10-27 06:21:04 +0000 | [diff] [blame] | 125 | xmlElementType type; /* type number in the DTD, must be third ! */ |
Daniel Veillard | 0bef131 | 1998-10-14 02:36:47 +0000 | [diff] [blame] | 126 | struct xmlDoc *doc; /* the containing document */ |
Daniel Veillard | 260a68f | 1998-08-13 03:39:55 +0000 | [diff] [blame] | 127 | struct xmlNode *parent; /* child->parent link */ |
| 128 | struct xmlNode *next; /* next sibling link */ |
Daniel Veillard | 0bef131 | 1998-10-14 02:36:47 +0000 | [diff] [blame] | 129 | struct xmlNode *prev; /* previous sibling link */ |
Daniel Veillard | 260a68f | 1998-08-13 03:39:55 +0000 | [diff] [blame] | 130 | struct xmlNode *childs; /* parent->childs link */ |
| 131 | struct xmlAttr *properties; /* properties list */ |
Daniel Veillard | 260a68f | 1998-08-13 03:39:55 +0000 | [diff] [blame] | 132 | 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 | */ |
| 141 | typedef struct xmlDoc { |
Daniel Veillard | 27fb075 | 1998-10-17 06:47:46 +0000 | [diff] [blame] | 142 | #ifndef XML_WITHOUT_CORBA |
| 143 | void *_private; /* for Corba, must be first ! */ |
| 144 | void *vepv; /* for Corba, must be next ! */ |
| 145 | #endif |
Daniel Veillard | ccb0963 | 1998-10-27 06:21:04 +0000 | [diff] [blame] | 146 | xmlElementType type; /* XML_DOCUMENT_NODE, must be second ! */ |
Daniel Veillard | 260a68f | 1998-08-13 03:39:55 +0000 | [diff] [blame] | 147 | char *name; /* name/filename/URI of the document */ |
| 148 | const CHAR *version; /* the XML version string */ |
| 149 | const CHAR *encoding; /* encoding, if any */ |
Daniel Veillard | 15a8df4 | 1998-09-24 19:15:06 +0000 | [diff] [blame] | 150 | int compression;/* level of zlib compression */ |
Daniel Veillard | 260a68f | 1998-08-13 03:39:55 +0000 | [diff] [blame] | 151 | 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 | */ |
| 161 | extern xmlNsPtr baseDTD; |
| 162 | extern int oldXMLWDcompatibility;/* maintain compatibility with old WD */ |
| 163 | extern int xmlIndentTreeOutput; /* try to indent the tree dumps */ |
| 164 | |
| 165 | /* |
Daniel Veillard | 1625364 | 1998-10-28 22:58:05 +0000 | [diff] [blame] | 166 | * Creating/freeing new structures |
Daniel Veillard | 260a68f | 1998-08-13 03:39:55 +0000 | [diff] [blame] | 167 | */ |
| 168 | extern xmlDtdPtr xmlNewDtd(xmlDocPtr doc, const CHAR *name, |
| 169 | const CHAR *ExternalID, const CHAR *SystemID); |
| 170 | extern void xmlFreeDtd(xmlDtdPtr cur); |
| 171 | extern xmlNsPtr xmlNewGlobalNs(xmlDocPtr doc, const CHAR *href, const CHAR *AS); |
| 172 | extern xmlNsPtr xmlNewNs(xmlNodePtr node, const CHAR *href, const CHAR *AS); |
| 173 | extern void xmlFreeNs(xmlNsPtr cur); |
| 174 | extern xmlDocPtr xmlNewDoc(const CHAR *version); |
| 175 | extern void xmlFreeDoc(xmlDocPtr cur); |
Daniel Veillard | ccb0963 | 1998-10-27 06:21:04 +0000 | [diff] [blame] | 176 | extern xmlAttrPtr xmlNewDocProp(xmlDocPtr doc, const CHAR *name, |
| 177 | const CHAR *value); |
Daniel Veillard | 260a68f | 1998-08-13 03:39:55 +0000 | [diff] [blame] | 178 | extern xmlAttrPtr xmlNewProp(xmlNodePtr node, const CHAR *name, |
| 179 | const CHAR *value); |
Daniel Veillard | 260a68f | 1998-08-13 03:39:55 +0000 | [diff] [blame] | 180 | extern void xmlFreePropList(xmlAttrPtr cur); |
| 181 | extern void xmlFreeProp(xmlAttrPtr cur); |
Daniel Veillard | 1625364 | 1998-10-28 22:58:05 +0000 | [diff] [blame] | 182 | |
| 183 | /* |
| 184 | * Creating new nodes |
| 185 | */ |
Daniel Veillard | 0bef131 | 1998-10-14 02:36:47 +0000 | [diff] [blame] | 186 | extern xmlNodePtr xmlNewDocNode(xmlDocPtr doc, xmlNsPtr ns, |
| 187 | const CHAR *name, CHAR *content); |
Daniel Veillard | ccb0963 | 1998-10-27 06:21:04 +0000 | [diff] [blame] | 188 | extern xmlNodePtr xmlNewNode(xmlNsPtr ns, const CHAR *name); |
Daniel Veillard | 1625364 | 1998-10-28 22:58:05 +0000 | [diff] [blame] | 189 | extern xmlNodePtr xmlNewChild(xmlNodePtr parent, xmlNsPtr ns, |
| 190 | const CHAR *name, CHAR *content); |
Daniel Veillard | 0bef131 | 1998-10-14 02:36:47 +0000 | [diff] [blame] | 191 | extern xmlNodePtr xmlNewDocText(xmlDocPtr doc, const CHAR *content); |
Daniel Veillard | 260a68f | 1998-08-13 03:39:55 +0000 | [diff] [blame] | 192 | extern xmlNodePtr xmlNewText(const CHAR *content); |
Daniel Veillard | 0bef131 | 1998-10-14 02:36:47 +0000 | [diff] [blame] | 193 | extern xmlNodePtr xmlNewDocTextLen(xmlDocPtr doc, const CHAR *content, int len); |
Daniel Veillard | 260a68f | 1998-08-13 03:39:55 +0000 | [diff] [blame] | 194 | extern xmlNodePtr xmlNewTextLen(const CHAR *content, int len); |
Daniel Veillard | 0bef131 | 1998-10-14 02:36:47 +0000 | [diff] [blame] | 195 | extern xmlNodePtr xmlNewDocComment(xmlDocPtr doc, CHAR *content); |
Daniel Veillard | 260a68f | 1998-08-13 03:39:55 +0000 | [diff] [blame] | 196 | extern xmlNodePtr xmlNewComment(CHAR *content); |
Daniel Veillard | ccb0963 | 1998-10-27 06:21:04 +0000 | [diff] [blame] | 197 | extern xmlNodePtr xmlNewReference(xmlDocPtr doc, const CHAR *name); |
Daniel Veillard | 1625364 | 1998-10-28 22:58:05 +0000 | [diff] [blame] | 198 | |
| 199 | /* |
| 200 | * Navigating |
| 201 | */ |
Daniel Veillard | 260a68f | 1998-08-13 03:39:55 +0000 | [diff] [blame] | 202 | extern xmlNodePtr xmlGetLastChild(xmlNodePtr node); |
| 203 | extern int xmlNodeIsText(xmlNodePtr node); |
Daniel Veillard | 1625364 | 1998-10-28 22:58:05 +0000 | [diff] [blame] | 204 | |
| 205 | /* |
| 206 | * Changing the structure |
| 207 | */ |
| 208 | extern xmlNodePtr xmlAddChild(xmlNodePtr parent, xmlNodePtr cur); |
| 209 | extern void xmlUnlinkNode(xmlNodePtr cur); |
| 210 | |
| 211 | extern xmlNodePtr xmlTextMerge(xmlNodePtr first, xmlNodePtr second); |
Daniel Veillard | 260a68f | 1998-08-13 03:39:55 +0000 | [diff] [blame] | 212 | extern void xmlTextConcat(xmlNodePtr node, const CHAR *content, int len); |
Daniel Veillard | 1625364 | 1998-10-28 22:58:05 +0000 | [diff] [blame] | 213 | |
Daniel Veillard | 260a68f | 1998-08-13 03:39:55 +0000 | [diff] [blame] | 214 | extern void xmlFreeNodeList(xmlNodePtr cur); |
| 215 | extern void xmlFreeNode(xmlNodePtr cur); |
Daniel Veillard | 1625364 | 1998-10-28 22:58:05 +0000 | [diff] [blame] | 216 | |
| 217 | /* |
| 218 | * Namespaces |
| 219 | */ |
Daniel Veillard | 260a68f | 1998-08-13 03:39:55 +0000 | [diff] [blame] | 220 | extern xmlNsPtr xmlSearchNs(xmlDocPtr doc, xmlNodePtr node, |
| 221 | const CHAR *nameSpace); |
| 222 | extern xmlNsPtr xmlSearchNsByHref(xmlDocPtr doc, xmlNodePtr node, |
| 223 | const CHAR *href); |
| 224 | extern void xmlSetNs(xmlNodePtr node, xmlNsPtr ns); |
Daniel Veillard | 260a68f | 1998-08-13 03:39:55 +0000 | [diff] [blame] | 225 | |
Daniel Veillard | 1625364 | 1998-10-28 22:58:05 +0000 | [diff] [blame] | 226 | /* |
| 227 | * Changing the content. |
| 228 | */ |
| 229 | extern xmlAttrPtr xmlSetProp(xmlNodePtr node, const CHAR *name, |
| 230 | const CHAR *value); |
| 231 | extern const CHAR *xmlGetProp(xmlNodePtr node, const CHAR *name); |
| 232 | extern xmlNodePtr xmlStringGetNodeList(xmlDocPtr doc, const CHAR *value); |
| 233 | extern xmlNodePtr xmlStringLenGetNodeList(xmlDocPtr doc, const CHAR *value, |
| 234 | int len); |
| 235 | extern CHAR *xmlNodeListGetString(xmlDocPtr doc, xmlNodePtr list, int inLine); |
| 236 | extern void xmlNodeSetContent(xmlNodePtr cur, const CHAR *content); |
| 237 | extern void xmlNodeSetContentLen(xmlNodePtr cur, const CHAR *content, int len); |
| 238 | extern void xmlNodeAddContent(xmlNodePtr cur, const CHAR *content); |
| 239 | extern void xmlNodeAddContentLen(xmlNodePtr cur, const CHAR *content, int len); |
| 240 | extern CHAR *xmlNodeGetContent(xmlNodePtr cur); |
| 241 | |
| 242 | /* |
| 243 | * Internal, don't use |
| 244 | */ |
Daniel Veillard | 260a68f | 1998-08-13 03:39:55 +0000 | [diff] [blame] | 245 | extern void xmlBufferWriteCHAR(const CHAR *string); |
| 246 | extern void xmlBufferWriteChar(const char *string); |
| 247 | |
Daniel Veillard | 1625364 | 1998-10-28 22:58:05 +0000 | [diff] [blame] | 248 | /* |
| 249 | * Saving |
| 250 | */ |
Daniel Veillard | 151b1b0 | 1998-09-23 00:49:46 +0000 | [diff] [blame] | 251 | extern void xmlDocDumpMemory(xmlDocPtr cur, CHAR**mem, int *size); |
| 252 | extern void xmlDocDump(FILE *f, xmlDocPtr doc); |
| 253 | int xmlSaveFile(const char *filename, xmlDocPtr cur); |
| 254 | |
Daniel Veillard | 1625364 | 1998-10-28 22:58:05 +0000 | [diff] [blame] | 255 | /* |
| 256 | * Compression |
| 257 | */ |
Daniel Veillard | 15a8df4 | 1998-09-24 19:15:06 +0000 | [diff] [blame] | 258 | extern int xmlGetDocCompressMode (xmlDocPtr doc); |
| 259 | extern void xmlSetDocCompressMode (xmlDocPtr doc, int mode); |
Daniel Veillard | 151b1b0 | 1998-09-23 00:49:46 +0000 | [diff] [blame] | 260 | extern int xmlGetCompressMode(void); |
| 261 | extern void xmlSetCompressMode(int mode); |
Daniel Veillard | 260a68f | 1998-08-13 03:39:55 +0000 | [diff] [blame] | 262 | |
| 263 | #ifdef __cplusplus |
| 264 | } |
| 265 | #endif |
| 266 | |
| 267 | #endif /* __XML_TREE_H__ */ |
| 268 | |