4 #include "../util/util.h"
7 /* --------------------------------------------------------- */
9 /* xmlnodes - Document Object Model */
11 /* --------------------------------------------------------- */
13 #define NTYPE_ATTRIB 1
17 #define NTYPE_UNDEF -1
19 /* --------------------------------------------------------------------------
20 * Node structure. Do not use directly! Always use accessor macros
22 * -------------------------------------------------------------------------- */
23 typedef struct xmlnode_t
31 struct xmlnode_t
* parent
;
32 struct xmlnode_t
* firstchild
;
33 struct xmlnode_t
* lastchild
;
34 struct xmlnode_t
* prev
;
35 struct xmlnode_t
* next
;
36 struct xmlnode_t
* firstattrib
;
37 struct xmlnode_t
* lastattrib
;
40 /* Node creation routines */
41 xmlnode
xmlnode_wrap(xmlnode x
,const char* wrapper
);
42 xmlnode
xmlnode_new_tag(const char* name
);
43 xmlnode
xmlnode_new_tag_pool(pool p
, const char* name
);
44 xmlnode
xmlnode_insert_cdata(xmlnode parent
, const char* CDATA
, unsigned int size
);
45 xmlnode
xmlnode_insert_tag_node(xmlnode parent
, xmlnode node
);
46 void xmlnode_insert_node(xmlnode parent
, xmlnode node
);
47 xmlnode
xmlnode_str(char *str
, int len
);
48 xmlnode
xmlnode_file(char *file
);
49 char* xmlnode_file_borked(char *file
); /* same as _file but returns the parsing error */
50 xmlnode
xmlnode_dup(xmlnode x
); /* duplicate x */
51 xmlnode
xmlnode_dup_pool(pool p
, xmlnode x
);
53 /* Node Memory Pool */
54 pool
xmlnode_pool(xmlnode node
);
55 xmlnode
_xmlnode_new(pool p
, const char *name
, unsigned int type
);
58 void xmlnode_hide(xmlnode child
);
59 void xmlnode_hide_attrib(xmlnode parent
, const char *name
);
61 /* Node deletion routine, also frees the node pool! */
62 void xmlnode_free(xmlnode node
);xmlnode
xmlnode_insert_cdata(xmlnode parent
, const char* CDATA
, unsigned int size
);
63 xmlnode
xmlnode_insert_tag_node(xmlnode parent
, xmlnode node
);
64 void xmlnode_insert_node(xmlnode parent
, xmlnode node
);
65 xmlnode
xmlnode_str(char *str
, int len
);
66 xmlnode
xmlnode_file(char *file
);
67 char* xmlnode_file_borked(char *file
); /* same as _file but returns the parsing error */
68 xmlnode
xmlnode_dup(xmlnode x
); /* duplicate x */
69 xmlnode
xmlnode_dup_pool(pool p
, xmlnode x
);
71 /* Node Memory Pool */
72 pool
xmlnode_pool(xmlnode node
);
73 xmlnode
_xmlnode_new(pool p
, const char *name
, unsigned int type
);
76 void xmlnode_hide(xmlnode child
);
77 void xmlnode_hide_attrib(xmlnode parent
, const char *name
);
79 /* Node deletion routine, also frees the node pool! */
80 void xmlnode_free(xmlnode node
);
82 /* Locates a child tag by name and returns it */
83 xmlnode
xmlnode_get_tag(xmlnode parent
, const char* name
);
84 char* xmlnode_get_tag_data(xmlnode parent
, const char* name
);
86 /* Attribute accessors */
87 void xmlnode_put_attrib(xmlnode owner
, const char* name
, const char* value
);
88 char* xmlnode_get_attrib(xmlnode owner
, const char* name
);
89 void xmlnode_put_expat_attribs(xmlnode owner
, const char** atts
);
91 /* Bastard am I, but these are fun for internal use ;-) */
92 void xmlnode_put_vattrib(xmlnode owner
, const char* name
, void *value
);
93 void* xmlnode_get_vattrib(xmlnode owner
, const char* name
);
95 /* Node traversal routines */
96 xmlnode
xmlnode_get_firstattrib(xmlnode parent
);
97 xmlnode
xmlnode_get_firstchild(xmlnode parent
);
98 xmlnode
xmlnode_get_lastchild(xmlnode parent
);
99 xmlnode
xmlnode_get_nextsibling(xmlnode sibling
);
100 xmlnode
xmlnode_get_prevsibling(xmlnode sibling
);
101 xmlnode
xmlnode_get_parent(xmlnode node
);
103 /* Node information routines */
104 char* xmlnode_get_name(xmlnode node
);
105 char* xmlnode_get_data(xmlnode node
);
106 int xmlnode_get_datasz(xmlnode node
);
107 int xmlnode_get_type(xmlnode node
);
109 int xmlnode_has_children(xmlnode node
);
110 int xmlnode_has_attribs(xmlnode node
);
112 /* Node-to-string translation */
113 char* xmlnode2str(xmlnode node
);
115 /* Node-to-terminated-string translation
116 * -- useful for interfacing w/ scripting langs */
117 char* xmlnode2tstr(xmlnode node
);
119 int xmlnode_cmp(xmlnode a
, xmlnode b
); /* compares a and b for equality */
121 int xmlnode2file(char *file
, xmlnode node
); /* writes node to file */
123 /* Expat callbacks */
124 void expat_startElement(void* userdata
, const char* name
, const char** atts
);
125 void expat_endElement(void* userdata
, const char* name
);
126 void expat_charData(void* userdata
, const char* s
, int len
);