1998-08-13 07:39:55 +04:00
/*
* tree . h : describes the structures found in an tree resulting
* from an XML parsing .
*
* See Copyright for the status of this software .
*
1999-01-17 22:11:59 +03:00
* Daniel . Veillard @ w3 . org
1998-08-13 07:39:55 +04:00
*/
# ifndef __XML_TREE_H__
# define __XML_TREE_H__
# ifdef __cplusplus
extern " C " {
# endif
1999-01-17 22:11:59 +03:00
# include <stdio.h>
1998-08-13 07:39:55 +04:00
/*
1998-10-27 09:21:04 +03:00
* The different element types carried by an XML tree
*
* NOTE : This is synchronized with DOM Level1 values
* See http : //www.w3.org/TR/REC-DOM-Level-1/
*/
typedef enum {
XML_ELEMENT_NODE = 1 ,
XML_ATTRIBUTE_NODE = 2 ,
XML_TEXT_NODE = 3 ,
XML_CDATA_SECTION_NODE = 4 ,
XML_ENTITY_REF_NODE = 5 ,
XML_ENTITY_NODE = 6 ,
XML_PI_NODE = 7 ,
XML_COMMENT_NODE = 8 ,
XML_DOCUMENT_NODE = 9 ,
XML_DOCUMENT_TYPE_NODE = 10 ,
XML_DOCUMENT_FRAG_NODE = 11 ,
XML_NOTATION_NODE = 12
} xmlElementType ;
/*
1998-11-01 22:34:31 +03:00
* Size of an internal character representation .
*
* Currently we use 8 bit chars internal representation for memory efficiency ,
* but the parser is not tied to that , just define UNICODE to switch to
* a 16 bits internal representation . Note that with 8 bits wide
* CHARs one can still use UTF - 8 to handle correctly non ISO - Latin
* input .
1998-08-13 07:39:55 +04:00
*/
# ifdef UNICODE
typedef unsigned short CHAR ;
# else
typedef unsigned char CHAR ;
# endif
/*
* a DTD Notation definition
*/
1999-02-22 13:33:01 +03:00
typedef struct xmlNotation {
const CHAR * name ; /* Notation name */
const CHAR * PublicID ; /* Public identifier, if any */
const CHAR * SystemID ; /* System identifier, if any */
} xmlNotation ;
typedef xmlNotation * xmlNotationPtr ;
1998-08-13 07:39:55 +04:00
/*
* a DTD Attribute definition
*/
1999-02-22 13:33:01 +03:00
typedef enum {
XML_ATTRIBUTE_CDATA = 1 ,
XML_ATTRIBUTE_ID ,
XML_ATTRIBUTE_IDREF ,
XML_ATTRIBUTE_IDREFS ,
XML_ATTRIBUTE_ENTITY ,
XML_ATTRIBUTE_ENTITIES ,
XML_ATTRIBUTE_NMTOKEN ,
XML_ATTRIBUTE_NMTOKENS ,
XML_ATTRIBUTE_ENUMERATION ,
XML_ATTRIBUTE_NOTATION
} xmlAttributeType ;
typedef enum {
XML_ATTRIBUTE_NONE = 1 ,
XML_ATTRIBUTE_REQUIRED ,
XML_ATTRIBUTE_IMPLIED ,
XML_ATTRIBUTE_FIXED
} xmlAttributeDefault ;
typedef struct xmlEnumeration {
struct xmlEnumeration * next ; /* next one */
const CHAR * name ; /* Enumeration name */
} xmlEnumeration ;
typedef xmlEnumeration * xmlEnumerationPtr ;
typedef struct xmlAttribute {
const CHAR * elem ; /* Element holding the attribute */
const CHAR * name ; /* Attribute name */
1999-08-10 23:04:08 +04:00
struct xmlAttribute * next ; /* list of attributes of an element */
1999-02-22 13:33:01 +03:00
xmlAttributeType type ; /* The type */
xmlAttributeDefault def ; /* the default */
const CHAR * defaultValue ; /* or the default value */
xmlEnumerationPtr tree ; /* or the enumeration tree if any */
} xmlAttribute ;
typedef xmlAttribute * xmlAttributePtr ;
1999-01-17 22:11:59 +03:00
1998-08-13 07:39:55 +04:00
/*
* a DTD Element definition .
*/
1999-02-01 15:18:54 +03:00
typedef enum {
1999-02-22 13:33:01 +03:00
XML_ELEMENT_CONTENT_PCDATA = 1 ,
1999-02-01 15:18:54 +03:00
XML_ELEMENT_CONTENT_ELEMENT ,
XML_ELEMENT_CONTENT_SEQ ,
XML_ELEMENT_CONTENT_OR
} xmlElementContentType ;
1999-01-17 22:11:59 +03:00
1999-02-01 15:18:54 +03:00
typedef enum {
1999-02-22 13:33:01 +03:00
XML_ELEMENT_CONTENT_ONCE = 1 ,
1999-02-01 15:18:54 +03:00
XML_ELEMENT_CONTENT_OPT ,
XML_ELEMENT_CONTENT_MULT ,
XML_ELEMENT_CONTENT_PLUS
} xmlElementContentOccur ;
1999-01-17 22:11:59 +03:00
typedef struct xmlElementContent {
1999-02-01 15:18:54 +03:00
xmlElementContentType type ; /* PCDATA, ELEMENT, SEQ or OR */
xmlElementContentOccur ocur ; /* ONCE, OPT, MULT or PLUS */
const CHAR * name ; /* Element name */
1999-01-17 22:11:59 +03:00
struct xmlElementContent * c1 ; /* first child */
struct xmlElementContent * c2 ; /* second child */
1999-02-22 13:33:01 +03:00
} xmlElementContent ;
typedef xmlElementContent * xmlElementContentPtr ;
1999-01-17 22:11:59 +03:00
1999-02-01 15:18:54 +03:00
typedef enum {
1999-02-22 13:33:01 +03:00
XML_ELEMENT_TYPE_EMPTY = 1 ,
1999-02-01 15:18:54 +03:00
XML_ELEMENT_TYPE_ANY ,
XML_ELEMENT_TYPE_MIXED ,
XML_ELEMENT_TYPE_ELEMENT
} xmlElementTypeVal ;
1998-08-13 07:39:55 +04:00
typedef struct xmlElement {
1999-08-10 23:04:08 +04:00
const CHAR * name ; /* Element name */
xmlElementTypeVal type ; /* The type */
1999-01-17 22:11:59 +03:00
xmlElementContentPtr content ; /* the allowed element content */
1999-08-10 23:04:08 +04:00
xmlAttributePtr attributes ; /* List of the declared attributes */
1999-02-22 13:33:01 +03:00
} xmlElement ;
typedef xmlElement * xmlElementPtr ;
1998-08-13 07:39:55 +04:00
/*
* An XML namespace .
* Note that prefix = = NULL is valid , it defines the default namespace
* within the subtree ( until overriden ) .
*/
1999-02-01 15:18:54 +03:00
typedef enum {
1999-02-22 13:33:01 +03:00
XML_GLOBAL_NAMESPACE = 1 , /* old style global namespace */
1999-02-01 15:18:54 +03:00
XML_LOCAL_NAMESPACE /* new style local scoping */
} xmlNsType ;
1998-08-13 07:39:55 +04:00
typedef struct xmlNs {
struct xmlNs * next ; /* next Ns link for this node */
1999-02-01 15:18:54 +03:00
xmlNsType type ; /* global or local */
1998-08-13 07:39:55 +04:00
const CHAR * href ; /* URL for the namespace */
const CHAR * prefix ; /* prefix for the namespace */
1999-02-22 13:33:01 +03:00
} xmlNs ;
typedef xmlNs * xmlNsPtr ;
1998-08-13 07:39:55 +04:00
/*
* An XML DtD , as defined by < ! DOCTYPE .
*/
typedef struct xmlDtd {
const CHAR * name ; /* Name of the DTD */
const CHAR * ExternalID ; /* External identifier for PUBLIC DTD */
const CHAR * SystemID ; /* URI for a SYSTEM or PUBLIC DTD */
1999-02-22 13:33:01 +03:00
void * notations ; /* Hash table for notations if any */
1998-08-13 07:39:55 +04:00
void * elements ; /* Hash table for elements if any */
1999-02-22 13:33:01 +03:00
void * attributes ; /* Hash table for attributes if any */
1998-08-13 07:39:55 +04:00
void * entities ; /* Hash table for entities if any */
/* struct xmlDtd *next; * next link for this document */
1999-02-22 13:33:01 +03:00
} xmlDtd ;
typedef xmlDtd * xmlDtdPtr ;
1998-08-13 07:39:55 +04:00
/*
* A attribute of an XML node .
*/
typedef struct xmlAttr {
1998-10-17 10:47:46 +04:00
# ifndef XML_WITHOUT_CORBA
void * _private ; /* for Corba, must be first ! */
void * vepv ; /* for Corba, must be next ! */
# endif
1998-10-27 09:21:04 +03:00
xmlElementType type ; /* XML_ATTRIBUTE_NODE, must be third ! */
1998-08-13 07:39:55 +04:00
struct xmlNode * node ; /* attr->node link */
1999-08-10 23:04:08 +04:00
struct xmlAttr * next ; /* attribute list link */
1998-08-13 07:39:55 +04:00
const CHAR * name ; /* the name of the property */
1998-10-27 09:21:04 +03:00
struct xmlNode * val ; /* the value of the property */
1999-02-22 13:33:01 +03:00
} xmlAttr ;
typedef xmlAttr * xmlAttrPtr ;
1998-08-13 07:39:55 +04:00
1999-08-16 03:32:28 +04:00
/*
* An XML ID instance .
*/
typedef struct xmlID {
struct xmlID * next ; /* next ID */
const CHAR * value ; /* The ID name */
xmlAttrPtr attr ; /* The attribut holding it */
} xmlID ;
typedef xmlID * xmlIDPtr ;
1998-08-13 07:39:55 +04:00
/*
* A node in an XML tree .
*/
typedef struct xmlNode {
1998-10-17 10:47:46 +04:00
# ifndef XML_WITHOUT_CORBA
void * _private ; /* for Corba, must be first ! */
void * vepv ; /* for Corba, must be next ! */
# endif
1998-10-27 09:21:04 +03:00
xmlElementType type ; /* type number in the DTD, must be third ! */
1998-10-14 06:36:47 +04:00
struct xmlDoc * doc ; /* the containing document */
1998-08-13 07:39:55 +04:00
struct xmlNode * parent ; /* child->parent link */
struct xmlNode * next ; /* next sibling link */
1998-10-14 06:36:47 +04:00
struct xmlNode * prev ; /* previous sibling link */
1998-08-13 07:39:55 +04:00
struct xmlNode * childs ; /* parent->childs link */
1999-01-17 22:11:59 +03:00
struct xmlNode * last ; /* last child link */
1998-08-13 07:39:55 +04:00
struct xmlAttr * properties ; /* properties list */
const CHAR * name ; /* the name of the node, or the entity */
xmlNs * ns ; /* pointer to the associated namespace */
xmlNs * nsDef ; /* namespace definitions on this node */
CHAR * content ; /* the content */
1999-02-22 13:33:01 +03:00
} _xmlNode ;
typedef _xmlNode xmlNode ;
typedef _xmlNode * xmlNodePtr ;
1998-08-13 07:39:55 +04:00
/*
* An XML document .
*/
typedef struct xmlDoc {
1998-10-17 10:47:46 +04:00
# ifndef XML_WITHOUT_CORBA
void * _private ; /* for Corba, must be first ! */
void * vepv ; /* for Corba, must be next ! */
# endif
1998-10-27 09:21:04 +03:00
xmlElementType type ; /* XML_DOCUMENT_NODE, must be second ! */
1998-08-13 07:39:55 +04:00
char * name ; /* name/filename/URI of the document */
const CHAR * version ; /* the XML version string */
const CHAR * encoding ; /* encoding, if any */
1998-09-24 23:15:06 +04:00
int compression ; /* level of zlib compression */
1998-08-13 07:39:55 +04:00
int standalone ; /* standalone document (no external refs) */
1999-01-17 22:11:59 +03:00
struct xmlDtd * intSubset ; /* the document internal subset */
struct xmlDtd * extSubset ; /* the document external subset */
1998-08-13 07:39:55 +04:00
struct xmlNs * oldNs ; /* Global namespace, the old way */
struct xmlNode * root ; /* the document tree */
1999-08-16 03:32:28 +04:00
void * ids ; /* Hash table for ID attributes if any */
1999-02-22 13:33:01 +03:00
} _xmlDoc ;
typedef _xmlDoc xmlDoc ;
typedef xmlDoc * xmlDocPtr ;
1998-08-13 07:39:55 +04:00
1999-04-22 00:12:07 +04:00
/*
* A buffer structure
*/
typedef struct xmlBuffer {
CHAR * content ; /* The buffer content UTF8 */
unsigned int use ; /* The buffer size used */
unsigned int size ; /* The buffer size */
} _xmlBuffer ;
typedef _xmlBuffer xmlBuffer ;
typedef xmlBuffer * xmlBufferPtr ;
1998-08-13 07:39:55 +04:00
/*
* Variables .
*/
extern xmlNsPtr baseDTD ;
extern int oldXMLWDcompatibility ; /* maintain compatibility with old WD */
extern int xmlIndentTreeOutput ; /* try to indent the tree dumps */
1999-04-22 00:12:07 +04:00
/*
* Handling Buffers .
*/
xmlBufferPtr xmlBufferCreate ( void ) ;
void xmlBufferFree ( xmlBufferPtr buf ) ;
int xmlBufferDump ( FILE * file , xmlBufferPtr buf ) ;
void xmlBufferAdd ( xmlBufferPtr buf , const CHAR * str , int len ) ;
void xmlBufferCat ( xmlBufferPtr buf , const CHAR * str ) ;
void xmlBufferCCat ( xmlBufferPtr buf , const char * str ) ;
1999-07-27 23:52:06 +04:00
int xmlBufferShrink ( xmlBufferPtr buf , int len ) ;
void xmlBufferEmpty ( xmlBufferPtr buf ) ;
1999-04-22 00:12:07 +04:00
1998-08-13 07:39:55 +04:00
/*
1998-10-29 01:58:05 +03:00
* Creating / freeing new structures
1998-08-13 07:39:55 +04:00
*/
1999-02-22 13:33:01 +03:00
xmlDtdPtr xmlCreateIntSubset ( xmlDocPtr doc , const CHAR * name ,
1999-01-17 22:11:59 +03:00
const CHAR * ExternalID , const CHAR * SystemID ) ;
1999-02-22 13:33:01 +03:00
xmlDtdPtr xmlNewDtd ( xmlDocPtr doc , const CHAR * name ,
1998-08-13 07:39:55 +04:00
const CHAR * ExternalID , const CHAR * SystemID ) ;
1999-02-22 13:33:01 +03:00
void xmlFreeDtd ( xmlDtdPtr cur ) ;
xmlNsPtr xmlNewGlobalNs ( xmlDocPtr doc , const CHAR * href , const CHAR * prefix ) ;
xmlNsPtr xmlNewNs ( xmlNodePtr node , const CHAR * href , const CHAR * prefix ) ;
void xmlFreeNs ( xmlNsPtr cur ) ;
xmlDocPtr xmlNewDoc ( const CHAR * version ) ;
void xmlFreeDoc ( xmlDocPtr cur ) ;
xmlAttrPtr xmlNewDocProp ( xmlDocPtr doc , const CHAR * name ,
1998-10-27 09:21:04 +03:00
const CHAR * value ) ;
1999-02-22 13:33:01 +03:00
xmlAttrPtr xmlNewProp ( xmlNodePtr node , const CHAR * name ,
1998-08-13 07:39:55 +04:00
const CHAR * value ) ;
1999-02-22 13:33:01 +03:00
void xmlFreePropList ( xmlAttrPtr cur ) ;
void xmlFreeProp ( xmlAttrPtr cur ) ;
xmlAttrPtr xmlCopyProp ( xmlAttrPtr cur ) ;
xmlAttrPtr xmlCopyPropList ( xmlAttrPtr cur ) ;
xmlDtdPtr xmlCopyDtd ( xmlDtdPtr dtd ) ;
xmlDocPtr xmlCopyDoc ( xmlDocPtr doc , int recursive ) ;
1998-10-29 01:58:05 +03:00
/*
* Creating new nodes
*/
1999-02-22 13:33:01 +03:00
xmlNodePtr xmlNewDocNode ( xmlDocPtr doc , xmlNsPtr ns ,
1999-07-26 20:42:37 +04:00
const CHAR * name , const CHAR * content ) ;
1999-02-22 13:33:01 +03:00
xmlNodePtr xmlNewNode ( xmlNsPtr ns , const CHAR * name ) ;
xmlNodePtr xmlNewChild ( xmlNodePtr parent , xmlNsPtr ns ,
1999-07-26 20:42:37 +04:00
const CHAR * name , const CHAR * content ) ;
1999-02-22 13:33:01 +03:00
xmlNodePtr xmlNewDocText ( xmlDocPtr doc , const CHAR * content ) ;
xmlNodePtr xmlNewText ( const CHAR * content ) ;
xmlNodePtr xmlNewDocTextLen ( xmlDocPtr doc , const CHAR * content , int len ) ;
xmlNodePtr xmlNewTextLen ( const CHAR * content , int len ) ;
1999-04-05 16:20:10 +04:00
xmlNodePtr xmlNewDocComment ( xmlDocPtr doc , const CHAR * content ) ;
xmlNodePtr xmlNewComment ( const CHAR * content ) ;
1999-08-10 23:04:08 +04:00
xmlNodePtr xmlNewCDataBlock ( xmlDocPtr doc , const CHAR * content , int len ) ;
1999-02-22 13:33:01 +03:00
xmlNodePtr xmlNewReference ( xmlDocPtr doc , const CHAR * name ) ;
xmlNodePtr xmlCopyNode ( xmlNodePtr node , int recursive ) ;
xmlNodePtr xmlCopyNodeList ( xmlNodePtr node ) ;
1998-10-29 01:58:05 +03:00
/*
* Navigating
*/
1999-02-22 13:33:01 +03:00
xmlNodePtr xmlGetLastChild ( xmlNodePtr parent ) ;
int xmlNodeIsText ( xmlNodePtr node ) ;
1998-10-29 01:58:05 +03:00
/*
* Changing the structure
*/
1999-02-22 13:33:01 +03:00
xmlNodePtr xmlAddChild ( xmlNodePtr parent , xmlNodePtr cur ) ;
void xmlUnlinkNode ( xmlNodePtr cur ) ;
1998-10-29 01:58:05 +03:00
1999-02-22 13:33:01 +03:00
xmlNodePtr xmlTextMerge ( xmlNodePtr first , xmlNodePtr second ) ;
void xmlTextConcat ( xmlNodePtr node , const CHAR * content , int len ) ;
1998-10-29 01:58:05 +03:00
1999-02-22 13:33:01 +03:00
void xmlFreeNodeList ( xmlNodePtr cur ) ;
void xmlFreeNode ( xmlNodePtr cur ) ;
1998-10-29 01:58:05 +03:00
/*
* Namespaces
*/
1999-02-22 13:33:01 +03:00
xmlNsPtr xmlSearchNs ( xmlDocPtr doc , xmlNodePtr node ,
1998-08-13 07:39:55 +04:00
const CHAR * nameSpace ) ;
1999-02-22 13:33:01 +03:00
xmlNsPtr xmlSearchNsByHref ( xmlDocPtr doc , xmlNodePtr node ,
1998-08-13 07:39:55 +04:00
const CHAR * href ) ;
1999-02-22 13:33:01 +03:00
void xmlSetNs ( xmlNodePtr node , xmlNsPtr ns ) ;
xmlNsPtr xmlCopyNamespace ( xmlNsPtr cur ) ;
xmlNsPtr xmlCopyNamespaceList ( xmlNsPtr cur ) ;
1998-08-13 07:39:55 +04:00
1998-10-29 01:58:05 +03:00
/*
* Changing the content .
*/
1999-02-22 13:33:01 +03:00
xmlAttrPtr xmlSetProp ( xmlNodePtr node , const CHAR * name ,
1998-10-29 01:58:05 +03:00
const CHAR * value ) ;
1999-02-22 13:33:01 +03:00
CHAR * xmlGetProp ( xmlNodePtr node , const CHAR * name ) ;
xmlNodePtr xmlStringGetNodeList ( xmlDocPtr doc , const CHAR * value ) ;
xmlNodePtr xmlStringLenGetNodeList ( xmlDocPtr doc , const CHAR * value ,
1998-10-29 01:58:05 +03:00
int len ) ;
1999-02-22 13:33:01 +03:00
CHAR * xmlNodeListGetString ( xmlDocPtr doc , xmlNodePtr list , int inLine ) ;
void xmlNodeSetContent ( xmlNodePtr cur , const CHAR * content ) ;
void xmlNodeSetContentLen ( xmlNodePtr cur , const CHAR * content , int len ) ;
void xmlNodeAddContent ( xmlNodePtr cur , const CHAR * content ) ;
void xmlNodeAddContentLen ( xmlNodePtr cur , const CHAR * content , int len ) ;
CHAR * xmlNodeGetContent ( xmlNodePtr cur ) ;
1998-10-29 01:58:05 +03:00
/*
* Internal , don ' t use
*/
1999-04-22 00:12:07 +04:00
void xmlBufferWriteCHAR ( xmlBufferPtr buf , const CHAR * string ) ;
void xmlBufferWriteChar ( xmlBufferPtr buf , const char * string ) ;
1999-06-02 21:44:04 +04:00
void xmlBufferWriteQuotedString ( xmlBufferPtr buf , const CHAR * string ) ;
1998-08-13 07:39:55 +04:00
1998-10-29 01:58:05 +03:00
/*
* Saving
*/
1999-02-22 13:33:01 +03:00
void xmlDocDumpMemory ( xmlDocPtr cur , CHAR * * mem , int * size ) ;
void xmlDocDump ( FILE * f , xmlDocPtr cur ) ;
1998-09-23 04:49:46 +04:00
int xmlSaveFile ( const char * filename , xmlDocPtr cur ) ;
1998-10-29 01:58:05 +03:00
/*
* Compression
*/
1999-02-22 13:33:01 +03:00
int xmlGetDocCompressMode ( xmlDocPtr doc ) ;
void xmlSetDocCompressMode ( xmlDocPtr doc , int mode ) ;
int xmlGetCompressMode ( void ) ;
void xmlSetCompressMode ( int mode ) ;
1998-08-13 07:39:55 +04:00
# ifdef __cplusplus
}
# endif
# endif /* __XML_TREE_H__ */