18ROXML_STATIC ROXML_INT
void roxml_realloc_buf(
char **buf,
int *len,
int min_len)
21 *buf = realloc(*buf, *len + append);
22 memset(*buf + *len, 0, append);
37ROXML_STATIC ROXML_INT
void roxml_print_spaces(FILE *f,
char **buf,
int *offset,
int *len,
int lvl)
43 fwrite(
"\n", 1, 1, f);
44 for (i = 0; i < lvl; i++)
46 }
else if (buf && *buf) {
47 if (*offset + lvl + 1 >= *len)
48 roxml_realloc_buf(buf, len, lvl);
50 *(*buf + (*offset)++) =
'\n';
51 for (i = 0; i < lvl; i++)
52 *(*buf + (*offset)++) =
' ';
67ROXML_STATIC ROXML_INT
void roxml_write_string(FILE *f,
char **buf,
int *offset,
int *len,
char *str, ...)
73 min_len = vsnprintf(NULL, 0, str, args);
79 vfprintf(f, str, args);
80 }
else if (buf && *buf) {
81 if (*offset + min_len >= *len)
82 roxml_realloc_buf(buf, len, min_len);
83 *offset += vsprintf(*buf + *offset, str, args);
89ROXML_STATIC ROXML_INT
void roxml_write_other_node(
node_t *n, FILE *f,
char **buf,
int *offset,
int *len,
char *name)
95 char cdata_head[16] =
"\0";
96 char cdata_tail[8] =
"\0";
98 ROXML_GET_BASE_BUFFER(val);
101 strcpy(head,
"<!--");
116 strcpy(cdata_head,
"<![CDATA[");
117 strcpy(cdata_tail,
"]]>");
121 name[0] ? name :
"", name[0] ?
" " :
"", cdata_head, value, cdata_tail, tail);
124 ROXML_PUT_BASE_BUFFER(val);
127ROXML_STATIC ROXML_INT
void roxml_write_elm_name_open(
node_t *n, FILE *f,
char **buf,
int *offset,
int *len,
128 char *name,
char *ns)
138 roxml_write_string(f, buf, offset, len,
"<%s%s%s", ns[0] ? ns :
"", ns[0] ?
":" :
"", name);
141ROXML_STATIC ROXML_INT
void roxml_write_elm_name_close(
node_t *n, FILE *f,
char **buf,
int *offset,
int *len,
142 char *name,
char *ns)
153 n->
chld && ns[0] ? ns :
"", n->chld && ns[0] ?
":" :
"", n->chld ? name :
"", tail);
156ROXML_STATIC ROXML_INT
void roxml_write_elm_attr(
node_t *n, FILE *f,
char **buf,
int *offset,
int *len)
167 ROXML_GET_BASE_BUFFER(ns);
179 ns_node_attr ?
"xmlns" :
"",
180 ns_node_attr && arg[0] ?
":" :
"",
181 attr->ns ? ns :
"", attr->ns ?
":" :
"", arg, value);
186 ROXML_PUT_BASE_BUFFER(ns);
205 ROXML_GET_BASE_BUFFER(name);
209 ROXML_GET_BASE_BUFFER(ns);
214 roxml_write_elm_name_open(n, f, buf, offset, len, name, ns);
215 roxml_write_elm_attr(n, f, buf, offset, len);
223 int keep_human = human;
238 roxml_write_elm_name_close(n, f, buf, offset, len, name, ns);
239 ROXML_PUT_BASE_BUFFER(ns);
243 roxml_write_other_node(n, f, buf, offset, len, name);
246 ROXML_PUT_BASE_BUFFER(name);
249ROXML_STATIC ROXML_INT
void roxml_commit_nodes(
node_t *n, FILE *f,
char **buf,
int human,
int *size,
int *len)
253 if (n->
prnt == NULL) {
256 }
else if (n->
prnt->prnt == NULL) {
261 memcpy(&fakeroot, n,
sizeof(
node_t));
262 fakeroot.
sibl = NULL;
284 fout = fopen(dest,
"w");
288 roxml_commit_nodes(n, fout, NULL, human, &size, &len);
312 roxml_commit_nodes(n, NULL, buffer, human, &size, &len);
341 fout = fdopen(fd2,
"w");
345 roxml_commit_nodes(n, fout, NULL, human, &size, &len);
#define ROXML_INVALID_DOC
ROXML_API void roxml_release(void *data)
memory cleanning function
#define ROXML_DOCTYPE_NODE
ROXML_STATIC ROXML_INT void roxml_write_string(FILE *f, char **buf, int *offset, int *len, char *str,...)
string writter function
ROXML_API int roxml_commit_buffer(node_t *n, char **buffer, int human)
sync to a memory buffer function
ROXML_STATIC ROXML_INT void roxml_print_spaces(FILE *f, char **buf, int *offset, int *len, int lvl)
space printing function
ROXML_API int roxml_commit_changes(node_t *n, char *dest, char **buffer, int human)
sync function
ROXML_API int roxml_commit_fd(node_t *n, int fd, int human)
sync to file descriptor function
ROXML_API int roxml_commit_file(node_t *n, char *dest, int human)
sync to named file function
ROXML_STATIC ROXML_INT void roxml_write_node(node_t *n, FILE *f, char **buf, int human, int lvl, int *offset, int *len)
tree write function
ROXML_API char * roxml_get_content(node_t *n, char *buffer, int bufsize, int *size)
content getter function
ROXML_API char * roxml_get_name(node_t *n, char *buffer, int size)
name getter function