12#include "nyx_node_internal.h"
29static void nyx_xmldoc_delete_all(
nyx_xmldoc_t *xmldoc,
bool itself,
bool children,
bool attributes)
42 for(
nyx_xmldoc_t *curr_child = xmldoc->attributes, *next_child; curr_child; curr_child = next_child)
44 next_child = curr_child->next;
46 nyx_xmldoc_delete_all(curr_child,
true,
true,
true);
49 xmldoc->attributes = NULL;
58 for(
nyx_xmldoc_t *curr_child = xmldoc->children, *next_child; curr_child; curr_child = next_child)
60 next_child = curr_child->next;
62 nyx_xmldoc_delete_all(curr_child,
true,
true,
true);
65 xmldoc->children = NULL;
88 nyx_xmldoc_delete_all(xmldoc,
true,
true,
true);
102 if(xmldoc->name != NULL)
114 for(
nyx_xmldoc_t *curr_child = xmldoc->children, *next_child; curr_child; curr_child = next_child)
116 next_child = curr_child->next;
118 if(curr_child->type == NYX_XML_TEXT
120 curr_child->type == NYX_XML_CDATA
122 return curr_child->data;
133 nyx_xmldoc_delete_all(xmldoc,
false,
true,
false);
142 nyx_xmldoc_add_child(xmldoc, node);
157 if(child->type == NYX_XML_ATTR)
165 if(last_child != NULL)
167 while(last_child->next != NULL)
169 last_child = last_child->next;
172 last_child->next = child;
176 xmldoc->attributes = child;
189 if(last_child != NULL)
191 while(last_child->next != NULL)
193 last_child = last_child->next;
196 last_child->next = child;
200 xmldoc->children = child;
208 child->parent = xmldoc;
226 nyx_xmldoc_add_child(xmldoc, node);
232__NYX_INLINE__
void to_string_append_attribute(nyx_string_builder_t *sb,
const nyx_xmldoc_t *xmldoc)
234 for(
nyx_xmldoc_t *curr_child = xmldoc->attributes, *next_child; curr_child; curr_child = next_child)
236 next_child = curr_child->next;
238 nyx_string_builder_append(sb, NYX_SB_NO_ESCAPE,
" ", curr_child->name,
"=\"");
239 nyx_string_builder_append(sb, NYX_SB_ESCAPE_XML, curr_child->data);
240 nyx_string_builder_append(sb, NYX_SB_NO_ESCAPE,
"\"");
246__NYX_INLINE__
void to_string_append_content(nyx_string_builder_t *sb,
const nyx_xmldoc_t *xmldoc)
248 for(
nyx_xmldoc_t *curr_child = xmldoc->children, *next_child; curr_child; curr_child = next_child)
250 next_child = curr_child->next;
254 if(curr_child->type == NYX_XML_ELEM)
256 str_t node = nyx_xmldoc_to_string(curr_child);
258 nyx_string_builder_append(sb, NYX_SB_NO_ESCAPE, node);
265 else if(curr_child->type == NYX_XML_COMMENT)
267 nyx_string_builder_append(sb, NYX_SB_NO_ESCAPE,
"<!--", curr_child->data,
"-->");
269 else if(curr_child->type == NYX_XML_CDATA)
271 nyx_string_builder_append(sb, NYX_SB_NO_ESCAPE,
"<![CDATA[", curr_child->data,
"]]>");
273 else if(curr_child->type == NYX_XML_TEXT)
275 nyx_string_builder_append(sb, NYX_SB_ESCAPE_XML, curr_child->data);
286 nyx_string_builder_t *sb = nyx_string_builder_new();
290 if(xmldoc->self_closing)
292 nyx_string_builder_append(sb, NYX_SB_NO_ESCAPE,
"<", xmldoc->name); to_string_append_attribute(sb, xmldoc); nyx_string_builder_append(sb, NYX_SB_NO_ESCAPE,
" />");
296 nyx_string_builder_append(sb, NYX_SB_NO_ESCAPE,
"<", xmldoc->name); to_string_append_attribute(sb, xmldoc); nyx_string_builder_append(sb, NYX_SB_NO_ESCAPE,
">");
298 to_string_append_content(sb, xmldoc);
300 nyx_string_builder_append(sb, NYX_SB_NO_ESCAPE,
"</", xmldoc->name,
">");
305 str_t result = nyx_string_builder_to_string(sb);
307 nyx_string_builder_free(sb);
#define STR_t
Alias for const char *.
__NYX_NULLABLE__ buff_t nyx_memory_alloc(__NYX_ZEROABLE__ size_t size)
Similar to libc malloc except that a memory overflow causes the node to stop.
__NYX_ZEROABLE__ size_t nyx_memory_free(__NYX_NULLABLE__ buff_t buff)
Similar to libc free except that it returns the amount of memory freed.
__NYX_NULLABLE__ str_t nyx_string_dup(__NYX_NULLABLE__ STR_t s)
Similar to libc strdup.
#define str_t
Alias for char *.
Struct describing an XML document.