mirror of
https://github.com/zoriya/xmlParser.git
synced 2026-06-01 09:35:15 +00:00
Handling string nodes
This commit is contained in:
@@ -9,7 +9,8 @@ SRC = src/xmlparser.c \
|
|||||||
src/parsenode.c \
|
src/parsenode.c \
|
||||||
src/list_utility.c \
|
src/list_utility.c \
|
||||||
src/helper.c \
|
src/helper.c \
|
||||||
src/xmlproperties.c
|
src/xmlproperties.c \
|
||||||
|
src/rawnode.c
|
||||||
|
|
||||||
OBJ = $(SRC:%.c=%.o)
|
OBJ = $(SRC:%.c=%.o)
|
||||||
|
|
||||||
|
|||||||
@@ -12,4 +12,5 @@
|
|||||||
void xml_fillclosing_br(char *buffer, const char *name);
|
void xml_fillclosing_br(char *buffer, const char *name);
|
||||||
char *xml_getname(char **nodestr, bool *has_parameters, bool *has_childs);
|
char *xml_getname(char **nodestr, bool *has_parameters, bool *has_childs);
|
||||||
dictionary *xml_getproperties(char **nodestr, bool *can_have_child);
|
dictionary *xml_getproperties(char **nodestr, bool *can_have_child);
|
||||||
char *trimstr(char *str);
|
char *trimstr(char *str);
|
||||||
|
int xml_getstringdata(node *n, char **nodestr);
|
||||||
+1
-1
@@ -31,7 +31,7 @@ char *trimstr(char *str)
|
|||||||
}
|
}
|
||||||
trimed = malloc(sizeof(char) * (len + 1));
|
trimed = malloc(sizeof(char) * (len + 1));
|
||||||
len = 0;
|
len = 0;
|
||||||
for(int i = 0; str[i]; i++) {
|
for (int i = 0; str[i]; i++) {
|
||||||
if (str[i] != '\t' && str[i] != '\n' && str[i] != '\r') {
|
if (str[i] != '\t' && str[i] != '\n' && str[i] != '\r') {
|
||||||
trimed[len] = str[i];
|
trimed[len] = str[i];
|
||||||
len++;
|
len++;
|
||||||
|
|||||||
+28
-14
@@ -51,6 +51,20 @@ int xml_parsechild(node *n, char **nodestr, bool has_child)
|
|||||||
return (0);
|
return (0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
node *xml_parseproperties(node *n, char **str, bool has_params, bool has_childs)
|
||||||
|
{
|
||||||
|
if (has_params) {
|
||||||
|
n->properties = xml_getproperties(str, &has_childs);
|
||||||
|
if (!n->properties)
|
||||||
|
return (NULL);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
n->properties = NULL;
|
||||||
|
if (xml_parsechild(n, str, has_childs) < 0)
|
||||||
|
return (NULL);
|
||||||
|
return (n);
|
||||||
|
}
|
||||||
|
|
||||||
node *xml_parsenode(char **nodestr)
|
node *xml_parsenode(char **nodestr)
|
||||||
{
|
{
|
||||||
node *n = malloc(sizeof(node));
|
node *n = malloc(sizeof(node));
|
||||||
@@ -58,20 +72,20 @@ node *xml_parsenode(char **nodestr)
|
|||||||
bool has_childs;
|
bool has_childs;
|
||||||
char *p = my_strchr(*nodestr, '>');
|
char *p = my_strchr(*nodestr, '>');
|
||||||
|
|
||||||
if (!n || !p || (*nodestr)[0] != '<' || (*nodestr)[1] == '/')
|
if (*nodestr[0] == '<') {
|
||||||
return (NULL);
|
if (!n || !p || (*nodestr)[1] == '/')
|
||||||
*p = '\0';
|
|
||||||
*nodestr += 1;
|
|
||||||
if (!(n->name = xml_getname(nodestr, &has_params, &has_childs)))
|
|
||||||
return (NULL);
|
|
||||||
if (has_params) {
|
|
||||||
n->properties = xml_getproperties(nodestr, &has_childs);
|
|
||||||
if (!n->properties)
|
|
||||||
return (NULL);
|
return (NULL);
|
||||||
|
*p = '\0';
|
||||||
|
*nodestr += 1;
|
||||||
|
n->name = xml_getname(nodestr, &has_params, &has_childs);
|
||||||
|
if (!n->name)
|
||||||
|
return (NULL);
|
||||||
|
return (xml_parseproperties(n, nodestr, has_params, has_childs));
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
if (xml_getstringdata(n, nodestr) < 0)
|
||||||
|
return (NULL);
|
||||||
|
n->next = xml_parsenode(nodestr);
|
||||||
|
return (n);
|
||||||
}
|
}
|
||||||
else
|
|
||||||
n->properties = NULL;
|
|
||||||
if (xml_parsechild(n, nodestr, has_childs) < 0)
|
|
||||||
return (NULL);
|
|
||||||
return (n);
|
|
||||||
}
|
}
|
||||||
@@ -0,0 +1,29 @@
|
|||||||
|
/*
|
||||||
|
** EPITECH PROJECT, 2019
|
||||||
|
** xmlparser
|
||||||
|
** File description:
|
||||||
|
** rawnode
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include "xml.h"
|
||||||
|
#include "my.h"
|
||||||
|
#include <stdlib.h>
|
||||||
|
#include <stddef.h>
|
||||||
|
|
||||||
|
int xml_getstringdata(node *n, char **nodestr)
|
||||||
|
{
|
||||||
|
dictionary *prop = malloc(sizeof(dictionary));
|
||||||
|
char *p = my_strchr(*nodestr, '<');
|
||||||
|
|
||||||
|
if (!p)
|
||||||
|
return (-1);
|
||||||
|
*(p - 1) = '\0';
|
||||||
|
prop->key = my_strdup("data");
|
||||||
|
prop->value = my_strdup(*nodestr);
|
||||||
|
prop->next = NULL;
|
||||||
|
*nodestr = p;
|
||||||
|
n->name = my_strdup("data");
|
||||||
|
n->child = NULL;
|
||||||
|
n->properties = prop;
|
||||||
|
return (0);
|
||||||
|
}
|
||||||
@@ -1,4 +1,4 @@
|
|||||||
<?xml version="1.0" encoding="UTF-8"?>
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
<yes>
|
<yes>
|
||||||
<nop />
|
<nop />
|
||||||
</yes>
|
</yes>
|
||||||
|
|||||||
Reference in New Issue
Block a user