31 while (current != n) {
33 current = current->
sibl;
95 while (current->
sibl && current->
sibl != n)
96 current = current->
sibl;
115 current = current->
sibl;
136 }
else if (current) {
137 while (current->
sibl && current->
sibl != n)
138 current = current->
sibl;
183 if ((position == 0) || (position > nb)) {
185 }
else if (position == 1) {
186 return roxml_prepend_node(parent, n);
194 for (i = 1; i < position; i++) {
220ROXML_STATIC ROXML_INT
void roxml_generate_cmt_node(
node_t *n,
char *content)
222 int content_l = strlen(content);
224 n->
src.buf = malloc(
sizeof(
char) * (content_l + 8));
225 sprintf(n->
src.buf,
"<!--%s-->", content);
226 n->
end = content_l + 4;
229ROXML_STATIC ROXML_INT
void roxml_generate_txt_node(
node_t *n,
char *content)
231 int content_l = strlen(content);
233 n->
src.buf = malloc(
sizeof(
char) * (content_l + 1));
234 sprintf(n->
src.buf,
"%s", content);
235 n->
end = content_l + 1;
238ROXML_STATIC ROXML_INT
void roxml_generate_elm_node(
node_t *n,
char *name,
char *content)
241 int name_l = strlen(name);
244 content_l = strlen(content);
247 n->
src.buf = malloc(
sizeof(
char) * (name_l * 2 + content_l + 6));
248 sprintf(n->
src.buf,
"<%s>%s</%s>", name, content, name);
249 n->
end = name_l + content_l + 2;
254 new_txt->
end = name_l + content_l + 2;
256 n->
src.buf = malloc(
sizeof(
char) * (name_l + 5));
257 sprintf(n->
src.buf,
"<%s />", name);
262ROXML_STATIC ROXML_INT
void roxml_generate_pi_node(
node_t *n,
char *name,
char *content)
265 int name_l = strlen(name);
268 content_l = strlen(content);
271 n->
src.buf = malloc(
sizeof(
char) * (name_l + content_l + 8));
272 sprintf(n->
src.buf,
"<?%s %s?>", name, content);
273 n->
end = name_l + content_l + 3;
275 n->
src.buf = malloc(
sizeof(
char) * (name_l + 7));
276 sprintf(n->
src.buf,
"<?%s?>", name);
281ROXML_STATIC ROXML_INT
void roxml_generate_attr_node(
node_t *n,
int type,
char *name,
char *content)
284 int content_l = strlen(content);
285 int name_l = strlen(name);
292 n->
src.buf = malloc(
sizeof(
char) * (name_l + content_l + xmlns_l + 4));
293 sprintf(n->
src.buf,
"xmlns%s%s=\"%s\"", name_l ?
":" :
"", name, content);
296 ns->
id = ROXML_NS_ID;
299 strcpy(ns->
alias, name);
302 n->
src.buf = malloc(
sizeof(
char) * (name_l + content_l + 4));
303 sprintf(n->
src.buf,
"%s=\"%s\"", name, content);
308 new_txt->
end = name_l + content_l + 2 + xmlns_l;
309 n->
end = name_l + 1 + xmlns_l;
313ROXML_INT
int roxml_add_node_check(
node_t *parent,
int type,
char *name,
char *content)
332 if (!name || !content)
360 char *out = malloc(size + 1);
365 ret = roxml_add_node_check(parent, type, name, content);
369 parent = parent->
prnt;
371 if (parent == NULL) {
379 roxml_generate_attr_node(new_node, type, name, content);
381 roxml_generate_cmt_node(new_node, content);
383 roxml_generate_pi_node(new_node, name, content);
385 roxml_generate_txt_node(new_node, content);
387 roxml_generate_elm_node(new_node, name, content);
404 node_t *common_parent = n;
405 while (common_parent && common_parent != ns->
prnt)
406 common_parent = common_parent->
prnt;
407 if (common_parent != ns->
prnt)
#define ROXML_NON_ESCAPABLE_NODES
#define ROXML_INVALID_DOC
#define ROXML_ESCAPED_MOD
#define ROXML_DOCTYPE_NODE
ROXML_API int roxml_get_nodes_nb(node_t *n, int type)
number of nodes getter function
ROXML_API int roxml_get_attr_nb(node_t *n)
number of attribute getter function
ROXML_API int roxml_escape(const char *buf, int decode, char *out)
XML encoding/decoding function.
ROXML_INT node_t * roxml_create_node(int pos, void *src, int type)
internal function
ROXML_INT node_t * roxml_append_node(node_t *parent, node_t *n)
node append function
ROXML_INT node_t * roxml_create_root(node_t *n)
internal function
ROXML_INT node_t * roxml_set_parent(node_t *parent, node_t *n)
node parenting function
ROXML_INT void roxml_del_tree(node_t *n)
internal function
ROXML_INT void roxml_free_node(node_t *n)
internal function
ROXML_STATIC ROXML_INT node_t * roxml_parent_node(node_t *parent, node_t *n, int position)
node relocate function
ROXML_STATIC ROXML_INT void roxml_del_arg_node(node_t *n)
attribute node deletion function
ROXML_API node_t * roxml_add_node(node_t *parent, int position, int type, char *name, char *content)
add a node to the tree
ROXML_API void roxml_del_node(node_t *n)
node deletion function
ROXML_STATIC ROXML_INT void roxml_del_std_node(node_t *n)
node deletion function
ROXML_STATIC ROXML_INT node_t * roxml_get_real_prev_sibling(node_t *n)
get real sibling
ROXML_STATIC ROXML_INT void roxml_del_txt_node(node_t *n)
text node deletion function
ROXML_STATIC ROXML_INT void roxml_reset_ns(node_t *n, node_t *ns)
internal function
ROXML_API node_t * roxml_set_ns(node_t *n, node_t *ns)
namespace setter function
XML internal memory management module.