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 | /* |
| 19 | * Type definitions |
| 20 | */ |
| 21 | #ifdef UNICODE |
| 22 | typedef unsigned short CHAR; |
| 23 | #else |
| 24 | typedef 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 | |
| 45 | typedef 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 | |
| 60 | typedef 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 | */ |
| 70 | typedef 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 | */ |
| 82 | typedef 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 | |
| 96 | typedef 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 | */ |
| 111 | typedef 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 | */ |
| 125 | extern xmlNsPtr baseDTD; |
| 126 | extern int oldXMLWDcompatibility;/* maintain compatibility with old WD */ |
| 127 | extern int xmlIndentTreeOutput; /* try to indent the tree dumps */ |
| 128 | |
| 129 | /* |
| 130 | * Functions. |
| 131 | */ |
| 132 | extern xmlDtdPtr xmlNewDtd(xmlDocPtr doc, const CHAR *name, |
| 133 | const CHAR *ExternalID, const CHAR *SystemID); |
| 134 | extern void xmlFreeDtd(xmlDtdPtr cur); |
| 135 | extern xmlNsPtr xmlNewGlobalNs(xmlDocPtr doc, const CHAR *href, const CHAR *AS); |
| 136 | extern xmlNsPtr xmlNewNs(xmlNodePtr node, const CHAR *href, const CHAR *AS); |
| 137 | extern void xmlFreeNs(xmlNsPtr cur); |
| 138 | extern xmlDocPtr xmlNewDoc(const CHAR *version); |
| 139 | extern void xmlFreeDoc(xmlDocPtr cur); |
| 140 | extern xmlAttrPtr xmlNewProp(xmlNodePtr node, const CHAR *name, |
| 141 | const CHAR *value); |
| 142 | extern xmlAttrPtr xmlSetProp(xmlNodePtr node, const CHAR *name, |
| 143 | const CHAR *value); |
| 144 | extern const CHAR *xmlGetProp(xmlNodePtr node, const CHAR *name); |
| 145 | extern void xmlFreePropList(xmlAttrPtr cur); |
| 146 | extern void xmlFreeProp(xmlAttrPtr cur); |
| 147 | extern xmlNodePtr xmlNewNode(xmlNsPtr ns, const CHAR *name, CHAR *content); |
| 148 | extern xmlNodePtr xmlNewText(const CHAR *content); |
| 149 | extern xmlNodePtr xmlNewTextLen(const CHAR *content, int len); |
| 150 | extern xmlNodePtr xmlNewComment(CHAR *content); |
| 151 | extern xmlNodePtr xmlAddChild(xmlNodePtr parent, xmlNodePtr cur); |
| 152 | extern xmlNodePtr xmlGetLastChild(xmlNodePtr node); |
| 153 | extern int xmlNodeIsText(xmlNodePtr node); |
| 154 | extern void xmlTextConcat(xmlNodePtr node, const CHAR *content, int len); |
| 155 | extern void xmlFreeNodeList(xmlNodePtr cur); |
| 156 | extern void xmlFreeNode(xmlNodePtr cur); |
| 157 | extern void xmlNodeSetContent(xmlNodePtr cur, const CHAR *content); |
| 158 | extern void xmlNodeSetContentLen(xmlNodePtr cur, const CHAR *content, int len); |
| 159 | extern void xmlNodeAddContent(xmlNodePtr cur, const CHAR *content); |
| 160 | extern void xmlNodeAddContentLen(xmlNodePtr cur, const CHAR *content, int len); |
| 161 | extern xmlNsPtr xmlSearchNs(xmlDocPtr doc, xmlNodePtr node, |
| 162 | const CHAR *nameSpace); |
| 163 | extern xmlNsPtr xmlSearchNsByHref(xmlDocPtr doc, xmlNodePtr node, |
| 164 | const CHAR *href); |
| 165 | extern void xmlSetNs(xmlNodePtr node, xmlNsPtr ns); |
| 166 | extern xmlNodePtr xmlNewChild(xmlNodePtr parent, xmlNsPtr ns, |
| 167 | const CHAR *name, CHAR *content); |
| 168 | |
Daniel Veillard | 260a68f | 1998-08-13 03:39:55 +0000 | [diff] [blame] | 169 | extern void xmlBufferWriteCHAR(const CHAR *string); |
| 170 | extern void xmlBufferWriteChar(const char *string); |
| 171 | |
Daniel Veillard | 151b1b0 | 1998-09-23 00:49:46 +0000 | [diff] [blame] | 172 | extern void xmlDocDumpMemory(xmlDocPtr cur, CHAR**mem, int *size); |
| 173 | extern void xmlDocDump(FILE *f, xmlDocPtr doc); |
| 174 | int xmlSaveFile(const char *filename, xmlDocPtr cur); |
| 175 | |
| 176 | extern int xmlGetCompressMode(void); |
| 177 | extern void xmlSetCompressMode(int mode); |
Daniel Veillard | 260a68f | 1998-08-13 03:39:55 +0000 | [diff] [blame] | 178 | |
| 179 | #ifdef __cplusplus |
| 180 | } |
| 181 | #endif |
| 182 | |
| 183 | #endif /* __XML_TREE_H__ */ |
| 184 | |