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(xmlnode parent
, const char* name
);
46 xmlnode
xmlnode_insert_tag_node(xmlnode parent
, xmlnode node
);
47 void xmlnode_insert_node(xmlnode parent
, xmlnode node
);
48 xmlnode
xmlnode_str(char *str
, int len
);
49 xmlnode
xmlnode_file(char *file
);
50 char* xmlnode_file_borked(char *file
); /* same as _file but returns the parsing error */
51 xmlnode
xmlnode_dup(xmlnode x
); /* duplicate x */
52 xmlnode
xmlnode_dup_pool(pool p
, xmlnode x
);
54 /* Node Memory Pool */
55 pool
xmlnode_pool(xmlnode node
);
56 xmlnode
_xmlnode_new(pool p
, const char *name
, unsigned int type
);
59 void xmlnode_hide(xmlnode child
);
60 void xmlnode_hide_attrib(xmlnode parent
, const char *name
);
62 /* Node deletion routine, also frees the node pool! */
63 void xmlnode_free(xmlnode node
);xmlnode
xmlnode_insert_cdata(xmlnode parent
, const char* CDATA
, unsigned int size
);
64 xmlnode
xmlnode_insert_tag_node(xmlnode parent
, xmlnode node
);
65 void xmlnode_insert_node(xmlnode parent
, xmlnode node
);
66 xmlnode
xmlnode_str(char *str
, int len
);
67 xmlnode
xmlnode_file(char *file
);
68 char* xmlnode_file_borked(char *file
); /* same as _file but returns the parsing error */
69 xmlnode
xmlnode_dup(xmlnode x
); /* duplicate x */
70 xmlnode
xmlnode_dup_pool(pool p
, xmlnode x
);
72 /* Node Memory Pool */
73 pool
xmlnode_pool(xmlnode node
);
74 xmlnode
_xmlnode_new(pool p
, const char *name
, unsigned int type
);
77 void xmlnode_hide(xmlnode child
);
78 void xmlnode_hide_attrib(xmlnode parent
, const char *name
);
80 /* Node deletion routine, also frees the node pool! */
81 void xmlnode_free(xmlnode node
);
83 /* Locates a child tag by name and returns it */
84 xmlnode
xmlnode_get_tag(xmlnode parent
, const char* name
);
85 char* xmlnode_get_tag_data(xmlnode parent
, const char* name
);
87 /* Attribute accessors */
88 void xmlnode_put_attrib(xmlnode owner
, const char* name
, const char* value
);
89 char* xmlnode_get_attrib(xmlnode owner
, const char* name
);
90 void xmlnode_put_expat_attribs(xmlnode owner
, const char** atts
);
92 /* Bastard am I, but these are fun for internal use ;-) */
93 void xmlnode_put_vattrib(xmlnode owner
, const char* name
, void *value
);
94 void* xmlnode_get_vattrib(xmlnode owner
, const char* name
);
96 /* Node traversal routines */
97 xmlnode
xmlnode_get_firstattrib(xmlnode parent
);
98 xmlnode
xmlnode_get_firstchild(xmlnode parent
);
99 xmlnode
xmlnode_get_lastchild(xmlnode parent
);
100 xmlnode
xmlnode_get_nextsibling(xmlnode sibling
);
101 xmlnode
xmlnode_get_prevsibling(xmlnode sibling
);
102 xmlnode
xmlnode_get_parent(xmlnode node
);
104 /* Node information routines */
105 char* xmlnode_get_name(xmlnode node
);
106 char* xmlnode_get_data(xmlnode node
);
107 int xmlnode_get_datasz(xmlnode node
);
108 int xmlnode_get_type(xmlnode node
);
110 int xmlnode_has_children(xmlnode node
);
111 int xmlnode_has_attribs(xmlnode node
);
113 /* Node-to-string translation */
114 char* xmlnode2str(xmlnode node
);
116 /* Node-to-terminated-string translation
117 * -- useful for interfacing w/ scripting langs */
118 char* xmlnode2tstr(xmlnode node
);
120 int xmlnode_cmp(xmlnode a
, xmlnode b
); /* compares a and b for equality */
122 int xmlnode2file(char *file
, xmlnode node
); /* writes node to file */
124 /* Expat callbacks */
125 void expat_startElement(void* userdata
, const char* name
, const char** atts
);
126 void expat_endElement(void* userdata
, const char* name
);
127 void expat_charData(void* userdata
, const char* s
, int len
);