13#include "nyx_node_internal.h"
25 nyx_dict_set(result,
"<>", nyx_string_from(
nyx_string_dup(curr_node->name),
true));
29 for(
nyx_xmldoc_t *new_node = curr_node->children; new_node != NULL; new_node = new_node->next)
31 if(new_node->type == NYX_XML_TEXT)
33 STR_t content_s = (
STR_t) new_node->data - 0x0000;
34 size_t length = strlen(content_s);
35 str_t content_e = (
str_t) new_node->data + length;
37 while(length > 0 && (isspace((
unsigned char) *(content_s + 0)) || *(content_s + 0) ==
'"')) {
42 while(length > 0 && (isspace((
unsigned char) *(content_e - 1)) || *(content_e - 1) ==
'"')) {
51 nyx_dict_set(result,
"$", nyx_string_from(
nyx_string_dup(content_s),
true));
60 for(
nyx_xmldoc_t *attribute = curr_node->attributes; attribute != NULL; attribute = attribute->next)
62 nyx_string_builder_t *sb = nyx_string_builder_from(NYX_SB_ESCAPE_JSON,
"@", attribute->name);
64 str_t attribute_name = nyx_string_builder_to_string(sb);
67 nyx_dict_set(result, attribute_name, nyx_string_from(
nyx_string_dup(attribute->data),
true));
72 nyx_string_builder_free(sb);
77 if(curr_node->children)
81 for(
nyx_xmldoc_t *new_node = curr_node->children; new_node != NULL; new_node = new_node->next)
83 if(new_node->type == NYX_XML_ELEM)
87 nyx_dict_set(result,
"children", list = nyx_list_new());
90 nyx_list_push(list, transform(new_node));
104 return xmldoc != NULL ? transform(xmldoc) : NULL;
Struct describing a JSON dict object.
Struct describing a JSON list object.
#define STR_t
Alias for const char *.
__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 a JSON object.
Struct describing an XML document.