mirror of
https://gitea.psi.ch/ELOG/mxml.git
synced 2026-09-13 03:38:02 +00:00
synchronized mxml and rome
fixed bug in mxml_add_special_node_at
This commit is contained in:
parent
17ef5507af
commit
2c3793990f
310
mxml.c
310
mxml.c
@ -78,15 +78,7 @@
|
|||||||
|
|
||||||
#define XML_INDENT " "
|
#define XML_INDENT " "
|
||||||
|
|
||||||
/* local prototypes */
|
static int mxml_suppress_date_flag = 0; /* suppress writing date at the top of file. */
|
||||||
static PMXML_NODE read_error(PMXML_NODE root, const char *file_name, int line_number, char *error, int error_size, char *format, ...);
|
|
||||||
static void mxml_encode(char *src, int size, int translate);
|
|
||||||
static void mxml_decode(char *str);
|
|
||||||
static int mxml_write_subtree(MXML_WRITER *writer, PMXML_NODE tree, int indent);
|
|
||||||
static int mxml_write_line(MXML_WRITER *writer, const char *line);
|
|
||||||
static int mxml_start_element1(MXML_WRITER *writer, const char *name, int indent);
|
|
||||||
static int mxml_add_resultnode(PMXML_NODE node, const char *xml_path, PMXML_NODE **nodelist, int *found);
|
|
||||||
static int mxml_find_nodes1(PMXML_NODE tree, const char *xml_path, PMXML_NODE **nodelist, int *found);
|
|
||||||
|
|
||||||
/*------------------------------------------------------------------*/
|
/*------------------------------------------------------------------*/
|
||||||
|
|
||||||
@ -111,12 +103,11 @@ int mxml_write_line(MXML_WRITER *writer, const char *line)
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/*------------------------------------------------------------------*/
|
/*------------------------------------------------------------------*/
|
||||||
|
|
||||||
/**
|
|
||||||
* open a memory buffer and write XML header
|
|
||||||
*/
|
|
||||||
MXML_WRITER *mxml_open_buffer()
|
MXML_WRITER *mxml_open_buffer()
|
||||||
|
/* open a file and write XML header */
|
||||||
{
|
{
|
||||||
char str[256], line[1000];
|
char str[256], line[1000];
|
||||||
time_t now;
|
time_t now;
|
||||||
@ -138,7 +129,8 @@ MXML_WRITER *mxml_open_buffer()
|
|||||||
strcpy(str, ctime(&now));
|
strcpy(str, ctime(&now));
|
||||||
str[24] = 0;
|
str[24] = 0;
|
||||||
sprintf(line, "<!-- created by MXML on %s -->\n", str);
|
sprintf(line, "<!-- created by MXML on %s -->\n", str);
|
||||||
mxml_write_line(writer, line);
|
if (mxml_suppress_date_flag == 0)
|
||||||
|
mxml_write_line(writer, line);
|
||||||
|
|
||||||
/* initialize stack */
|
/* initialize stack */
|
||||||
writer->level = 0;
|
writer->level = 0;
|
||||||
@ -149,10 +141,16 @@ MXML_WRITER *mxml_open_buffer()
|
|||||||
|
|
||||||
/*------------------------------------------------------------------*/
|
/*------------------------------------------------------------------*/
|
||||||
|
|
||||||
/**
|
void mxml_suppress_date(int suppress)
|
||||||
* open a file and write XML header
|
/* suppress writing date at the top of file. */
|
||||||
*/
|
{
|
||||||
|
mxml_suppress_date_flag = suppress;
|
||||||
|
}
|
||||||
|
|
||||||
|
/*------------------------------------------------------------------*/
|
||||||
|
|
||||||
MXML_WRITER *mxml_open_file(const char *file_name)
|
MXML_WRITER *mxml_open_file(const char *file_name)
|
||||||
|
/* open a file and write XML header */
|
||||||
{
|
{
|
||||||
char str[256], line[1000];
|
char str[256], line[1000];
|
||||||
time_t now;
|
time_t now;
|
||||||
@ -178,7 +176,8 @@ MXML_WRITER *mxml_open_file(const char *file_name)
|
|||||||
strcpy(str, ctime(&now));
|
strcpy(str, ctime(&now));
|
||||||
str[24] = 0;
|
str[24] = 0;
|
||||||
sprintf(line, "<!-- created by MXML on %s -->\n", str);
|
sprintf(line, "<!-- created by MXML on %s -->\n", str);
|
||||||
mxml_write_line(writer, line);
|
if (mxml_suppress_date_flag == 0)
|
||||||
|
mxml_write_line(writer, line);
|
||||||
|
|
||||||
/* initialize stack */
|
/* initialize stack */
|
||||||
writer->level = 0;
|
writer->level = 0;
|
||||||
@ -189,10 +188,8 @@ MXML_WRITER *mxml_open_file(const char *file_name)
|
|||||||
|
|
||||||
/*------------------------------------------------------------------*/
|
/*------------------------------------------------------------------*/
|
||||||
|
|
||||||
/**
|
|
||||||
* convert '<' '>' '&' '"' ''' into &xx;
|
|
||||||
*/
|
|
||||||
void mxml_encode(char *src, int size, int translate)
|
void mxml_encode(char *src, int size, int translate)
|
||||||
|
/* convert '<' '>' '&' '"' ''' into &xx; */
|
||||||
{
|
{
|
||||||
char *ps, *pd;
|
char *ps, *pd;
|
||||||
static char *buffer = NULL;
|
static char *buffer = NULL;
|
||||||
@ -212,7 +209,7 @@ void mxml_encode(char *src, int size, int translate)
|
|||||||
pd = buffer;
|
pd = buffer;
|
||||||
for (ps = src ; *ps && (size_t)pd - (size_t)buffer < (size_t)(size-10) ; ps++) {
|
for (ps = src ; *ps && (size_t)pd - (size_t)buffer < (size_t)(size-10) ; ps++) {
|
||||||
|
|
||||||
if (translate) { /* tranlate "<", ">", "&", """, "'" */
|
if (translate) { // tranlate "<", ">", "&", """, "'"
|
||||||
switch (*ps) {
|
switch (*ps) {
|
||||||
case '<':
|
case '<':
|
||||||
strcpy(pd, "<");
|
strcpy(pd, "<");
|
||||||
@ -238,7 +235,7 @@ void mxml_encode(char *src, int size, int translate)
|
|||||||
*pd++ = *ps;
|
*pd++ = *ps;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
switch (*ps) { /* translate only illegal XML characters "<" and "&" */
|
switch (*ps) { // translate only illegal XML characters "<" and "&"
|
||||||
case '<':
|
case '<':
|
||||||
strcpy(pd, "<");
|
strcpy(pd, "<");
|
||||||
pd += 4;
|
pd += 4;
|
||||||
@ -259,10 +256,8 @@ void mxml_encode(char *src, int size, int translate)
|
|||||||
|
|
||||||
/*------------------------------------------------------------------*/
|
/*------------------------------------------------------------------*/
|
||||||
|
|
||||||
/**
|
|
||||||
* reverse of mxml_encode, strip leading or trailing '"'
|
|
||||||
*/
|
|
||||||
void mxml_decode(char *str)
|
void mxml_decode(char *str)
|
||||||
|
/* reverse of mxml_encode, strip leading or trailing '"' */
|
||||||
{
|
{
|
||||||
char *p;
|
char *p;
|
||||||
|
|
||||||
@ -297,10 +292,8 @@ void mxml_decode(char *str)
|
|||||||
|
|
||||||
/*------------------------------------------------------------------*/
|
/*------------------------------------------------------------------*/
|
||||||
|
|
||||||
/**
|
|
||||||
* set translation of <,>,",',&, on/off in writer
|
|
||||||
*/
|
|
||||||
int mxml_set_translate(MXML_WRITER *writer, int flag)
|
int mxml_set_translate(MXML_WRITER *writer, int flag)
|
||||||
|
/* set translation of <,>,",',&, on/off in writer */
|
||||||
{
|
{
|
||||||
int old_flag;
|
int old_flag;
|
||||||
|
|
||||||
@ -310,10 +303,8 @@ int mxml_set_translate(MXML_WRITER *writer, int flag)
|
|||||||
}
|
}
|
||||||
/*------------------------------------------------------------------*/
|
/*------------------------------------------------------------------*/
|
||||||
|
|
||||||
/**
|
|
||||||
* start a new XML element, must be followed by mxml_end_elemnt
|
|
||||||
*/
|
|
||||||
int mxml_start_element1(MXML_WRITER *writer, const char *name, int indent)
|
int mxml_start_element1(MXML_WRITER *writer, const char *name, int indent)
|
||||||
|
/* start a new XML element, must be followed by mxml_end_elemnt */
|
||||||
{
|
{
|
||||||
int i;
|
int i;
|
||||||
char line[1000], name_enc[1000];
|
char line[1000], name_enc[1000];
|
||||||
@ -363,10 +354,8 @@ int mxml_start_element_noindent(MXML_WRITER *writer, const char *name)
|
|||||||
|
|
||||||
/*------------------------------------------------------------------*/
|
/*------------------------------------------------------------------*/
|
||||||
|
|
||||||
/**
|
|
||||||
* close an open XML element
|
|
||||||
*/
|
|
||||||
int mxml_end_element(MXML_WRITER *writer)
|
int mxml_end_element(MXML_WRITER *writer)
|
||||||
|
/* close an open XML element */
|
||||||
{
|
{
|
||||||
int i;
|
int i;
|
||||||
char line[1000];
|
char line[1000];
|
||||||
@ -404,12 +393,10 @@ int mxml_end_element(MXML_WRITER *writer)
|
|||||||
|
|
||||||
/*------------------------------------------------------------------*/
|
/*------------------------------------------------------------------*/
|
||||||
|
|
||||||
/**
|
|
||||||
* write an attribute to the currently open XML element
|
|
||||||
*/
|
|
||||||
int mxml_write_attribute(MXML_WRITER *writer, const char *name, const char *value)
|
int mxml_write_attribute(MXML_WRITER *writer, const char *name, const char *value)
|
||||||
|
/* write an attribute to the currently open XML element */
|
||||||
{
|
{
|
||||||
char name_enc[1000], val_enc[1000], line[2000];
|
char name_enc[4000], val_enc[4000], line[8000];
|
||||||
|
|
||||||
if (!writer->element_is_open)
|
if (!writer->element_is_open)
|
||||||
return FALSE;
|
return FALSE;
|
||||||
@ -426,10 +413,8 @@ int mxml_write_attribute(MXML_WRITER *writer, const char *name, const char *valu
|
|||||||
|
|
||||||
/*------------------------------------------------------------------*/
|
/*------------------------------------------------------------------*/
|
||||||
|
|
||||||
/**
|
|
||||||
* write value of an XML element, like <[name]>[value]</[name]>
|
|
||||||
*/
|
|
||||||
int mxml_write_value(MXML_WRITER *writer, const char *data)
|
int mxml_write_value(MXML_WRITER *writer, const char *data)
|
||||||
|
/* write value of an XML element, like <[name]>[value]</[name]> */
|
||||||
{
|
{
|
||||||
static char *data_enc;
|
static char *data_enc;
|
||||||
static int data_size = 0;
|
static int data_size = 0;
|
||||||
@ -457,10 +442,24 @@ int mxml_write_value(MXML_WRITER *writer, const char *data)
|
|||||||
|
|
||||||
/*------------------------------------------------------------------*/
|
/*------------------------------------------------------------------*/
|
||||||
|
|
||||||
/**
|
int mxml_write_empty_line(MXML_WRITER *writer)
|
||||||
* write a comment to an XML file, enclosed in "<!--" and "-->"
|
/* write empty line */
|
||||||
*/
|
{
|
||||||
|
if (writer->element_is_open) {
|
||||||
|
mxml_write_line(writer, ">\n");
|
||||||
|
writer->element_is_open = FALSE;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (mxml_write_line(writer, "\n") != 1)
|
||||||
|
return FALSE;
|
||||||
|
|
||||||
|
return TRUE;
|
||||||
|
}
|
||||||
|
|
||||||
|
/*------------------------------------------------------------------*/
|
||||||
|
|
||||||
int mxml_write_comment(MXML_WRITER *writer, const char *string)
|
int mxml_write_comment(MXML_WRITER *writer, const char *string)
|
||||||
|
/* write a comment to an XML file, enclosed in "<!--" and "-->" */
|
||||||
{
|
{
|
||||||
int i;
|
int i;
|
||||||
char line[1000];
|
char line[1000];
|
||||||
@ -485,10 +484,8 @@ int mxml_write_comment(MXML_WRITER *writer, const char *string)
|
|||||||
|
|
||||||
/*------------------------------------------------------------------*/
|
/*------------------------------------------------------------------*/
|
||||||
|
|
||||||
/**
|
|
||||||
* close a file opened with mxml_open_writer
|
|
||||||
*/
|
|
||||||
char *mxml_close_buffer(MXML_WRITER *writer)
|
char *mxml_close_buffer(MXML_WRITER *writer)
|
||||||
|
/* close a file opened with mxml_open_writer */
|
||||||
{
|
{
|
||||||
int i;
|
int i;
|
||||||
char *p;
|
char *p;
|
||||||
@ -510,10 +507,8 @@ char *mxml_close_buffer(MXML_WRITER *writer)
|
|||||||
|
|
||||||
/*------------------------------------------------------------------*/
|
/*------------------------------------------------------------------*/
|
||||||
|
|
||||||
/**
|
|
||||||
* close a file opened with mxml_open_writer
|
|
||||||
*/
|
|
||||||
int mxml_close_file(MXML_WRITER *writer)
|
int mxml_close_file(MXML_WRITER *writer)
|
||||||
|
/* close a file opened with mxml_open_writer */
|
||||||
{
|
{
|
||||||
int i;
|
int i;
|
||||||
|
|
||||||
@ -534,10 +529,8 @@ int mxml_close_file(MXML_WRITER *writer)
|
|||||||
|
|
||||||
/*------------------------------------------------------------------*/
|
/*------------------------------------------------------------------*/
|
||||||
|
|
||||||
/**
|
|
||||||
* create root node of an XML tree
|
|
||||||
*/
|
|
||||||
PMXML_NODE mxml_create_root_node()
|
PMXML_NODE mxml_create_root_node()
|
||||||
|
/* create root node of an XML tree */
|
||||||
{
|
{
|
||||||
PMXML_NODE root;
|
PMXML_NODE root;
|
||||||
|
|
||||||
@ -550,10 +543,8 @@ PMXML_NODE mxml_create_root_node()
|
|||||||
|
|
||||||
/*------------------------------------------------------------------*/
|
/*------------------------------------------------------------------*/
|
||||||
|
|
||||||
/**
|
PMXML_NODE mxml_add_special_node_at(PMXML_NODE parent, int node_type, char *node_name, char *value, int index)
|
||||||
* add a subnode (child) to an existing parent node as a specific position
|
/* add a subnode (child) to an existing parent node as a specific position */
|
||||||
*/
|
|
||||||
PMXML_NODE mxml_add_special_node_at(PMXML_NODE parent, int node_type, const char *node_name, const char *value, int index)
|
|
||||||
{
|
{
|
||||||
PMXML_NODE pnode, pchild;
|
PMXML_NODE pnode, pchild;
|
||||||
int i, j;
|
int i, j;
|
||||||
@ -600,40 +591,32 @@ PMXML_NODE mxml_add_special_node_at(PMXML_NODE parent, int node_type, const char
|
|||||||
|
|
||||||
/*------------------------------------------------------------------*/
|
/*------------------------------------------------------------------*/
|
||||||
|
|
||||||
/**
|
PMXML_NODE mxml_add_special_node(PMXML_NODE parent, int node_type, char *node_name, char *value)
|
||||||
* add a subnode (child) to an existing parent node at the end
|
/* add a subnode (child) to an existing parent node at the end */
|
||||||
*/
|
|
||||||
PMXML_NODE mxml_add_special_node(PMXML_NODE parent, int node_type, const char *node_name, const char *value)
|
|
||||||
{
|
{
|
||||||
return mxml_add_special_node_at(parent, node_type, node_name, value, parent->n_children);
|
return mxml_add_special_node_at(parent, node_type, node_name, value, parent->n_children);
|
||||||
}
|
}
|
||||||
|
|
||||||
/*------------------------------------------------------------------*/
|
/*------------------------------------------------------------------*/
|
||||||
|
|
||||||
/**
|
PMXML_NODE mxml_add_node(PMXML_NODE parent, char *node_name, char *value)
|
||||||
* write value of an XML element, like <[name]>[value]</[name]>
|
/* add a subnode (child) to an existing parent node at the end */
|
||||||
*/
|
|
||||||
PMXML_NODE mxml_add_node(PMXML_NODE parent, const char *node_name, const char *value)
|
|
||||||
{
|
{
|
||||||
return mxml_add_special_node_at(parent, ELEMENT_NODE, node_name, value, parent->n_children);
|
return mxml_add_special_node_at(parent, ELEMENT_NODE, node_name, value, parent->n_children);
|
||||||
}
|
}
|
||||||
|
|
||||||
/*------------------------------------------------------------------*/
|
/*------------------------------------------------------------------*/
|
||||||
|
|
||||||
/**
|
PMXML_NODE mxml_add_node_at(PMXML_NODE parent, char *node_name, char *value, int index)
|
||||||
* add a subnode (child) to an existing parent node at the end
|
/* add a subnode (child) to an existing parent node at the end */
|
||||||
*/
|
|
||||||
PMXML_NODE mxml_add_node_at(PMXML_NODE parent, const char *node_name, const char *value, int index)
|
|
||||||
{
|
{
|
||||||
return mxml_add_special_node_at(parent, ELEMENT_NODE, node_name, value, index);
|
return mxml_add_special_node_at(parent, ELEMENT_NODE, node_name, value, index);
|
||||||
}
|
}
|
||||||
|
|
||||||
/*------------------------------------------------------------------*/
|
/*------------------------------------------------------------------*/
|
||||||
|
|
||||||
/**
|
|
||||||
* add a whole node tree to an existing parent node at a specific position
|
|
||||||
*/
|
|
||||||
int mxml_add_tree_at(PMXML_NODE parent, PMXML_NODE tree, int index)
|
int mxml_add_tree_at(PMXML_NODE parent, PMXML_NODE tree, int index)
|
||||||
|
/* add a whole node tree to an existing parent node at a specific position */
|
||||||
{
|
{
|
||||||
PMXML_NODE pchild;
|
PMXML_NODE pchild;
|
||||||
int i, j;
|
int i, j;
|
||||||
@ -687,20 +670,16 @@ int mxml_add_tree_at(PMXML_NODE parent, PMXML_NODE tree, int index)
|
|||||||
|
|
||||||
/*------------------------------------------------------------------*/
|
/*------------------------------------------------------------------*/
|
||||||
|
|
||||||
/**
|
|
||||||
* add a whole node tree to an existing parent node at the end
|
|
||||||
*/
|
|
||||||
int mxml_add_tree(PMXML_NODE parent, PMXML_NODE tree)
|
int mxml_add_tree(PMXML_NODE parent, PMXML_NODE tree)
|
||||||
|
/* add a whole node tree to an existing parent node at the end */
|
||||||
{
|
{
|
||||||
return mxml_add_tree_at(parent, tree, parent->n_children);
|
return mxml_add_tree_at(parent, tree, parent->n_children);
|
||||||
}
|
}
|
||||||
|
|
||||||
/*------------------------------------------------------------------*/
|
/*------------------------------------------------------------------*/
|
||||||
|
|
||||||
/**
|
int mxml_add_attribute(PMXML_NODE pnode, char *attrib_name, char *attrib_value)
|
||||||
* add an attribute to an existing node
|
/* add an attribute to an existing node */
|
||||||
*/
|
|
||||||
int mxml_add_attribute(PMXML_NODE pnode, const char *attrib_name, const char *attrib_value)
|
|
||||||
{
|
{
|
||||||
if (pnode->n_attributes == 0) {
|
if (pnode->n_attributes == 0) {
|
||||||
pnode->attribute_name = (char*)malloc(MXML_NAME_LENGTH);
|
pnode->attribute_name = (char*)malloc(MXML_NAME_LENGTH);
|
||||||
@ -720,10 +699,8 @@ int mxml_add_attribute(PMXML_NODE pnode, const char *attrib_name, const char *at
|
|||||||
|
|
||||||
/*------------------------------------------------------------------*/
|
/*------------------------------------------------------------------*/
|
||||||
|
|
||||||
/**
|
|
||||||
* return number of subnodes (children) of a node
|
|
||||||
*/
|
|
||||||
int mxml_get_number_of_children(PMXML_NODE pnode)
|
int mxml_get_number_of_children(PMXML_NODE pnode)
|
||||||
|
/* return number of subnodes (children) of a node */
|
||||||
{
|
{
|
||||||
assert(pnode);
|
assert(pnode);
|
||||||
return pnode->n_children;
|
return pnode->n_children;
|
||||||
@ -731,10 +708,8 @@ int mxml_get_number_of_children(PMXML_NODE pnode)
|
|||||||
|
|
||||||
/*------------------------------------------------------------------*/
|
/*------------------------------------------------------------------*/
|
||||||
|
|
||||||
/**
|
|
||||||
* return number of subnodes (children) of a node
|
|
||||||
*/
|
|
||||||
PMXML_NODE mxml_subnode(PMXML_NODE pnode, int index)
|
PMXML_NODE mxml_subnode(PMXML_NODE pnode, int index)
|
||||||
|
/* return number of subnodes (children) of a node */
|
||||||
{
|
{
|
||||||
assert(pnode);
|
assert(pnode);
|
||||||
if (index < pnode->n_children)
|
if (index < pnode->n_children)
|
||||||
@ -744,8 +719,9 @@ PMXML_NODE mxml_subnode(PMXML_NODE pnode, int index)
|
|||||||
|
|
||||||
/*------------------------------------------------------------------*/
|
/*------------------------------------------------------------------*/
|
||||||
|
|
||||||
|
int mxml_find_nodes1(PMXML_NODE tree, char *xml_path, PMXML_NODE **nodelist, int *found);
|
||||||
|
|
||||||
int mxml_add_resultnode(PMXML_NODE node, const char *xml_path, PMXML_NODE **nodelist, int *found)
|
int mxml_add_resultnode(PMXML_NODE node, char *xml_path, PMXML_NODE **nodelist, int *found)
|
||||||
{
|
{
|
||||||
/* if at end of path, add this node */
|
/* if at end of path, add this node */
|
||||||
if (*xml_path == 0) {
|
if (*xml_path == 0) {
|
||||||
@ -766,7 +742,8 @@ int mxml_add_resultnode(PMXML_NODE node, const char *xml_path, PMXML_NODE **node
|
|||||||
|
|
||||||
/*------------------------------------------------------------------*/
|
/*------------------------------------------------------------------*/
|
||||||
|
|
||||||
/**
|
int mxml_find_nodes1(PMXML_NODE tree, char *xml_path, PMXML_NODE **nodelist, int *found)
|
||||||
|
/*
|
||||||
Return list of XML nodes with a subset of XPATH specifications.
|
Return list of XML nodes with a subset of XPATH specifications.
|
||||||
Following elemets are possible
|
Following elemets are possible
|
||||||
|
|
||||||
@ -777,11 +754,9 @@ int mxml_add_resultnode(PMXML_NODE node, const char *xml_path, PMXML_NODE **node
|
|||||||
/<node>[<subnode>=<value>]/<node> Find subnode of the above
|
/<node>[<subnode>=<value>]/<node> Find subnode of the above
|
||||||
/<node>[@<attrib>=<value>]/<node> Find a node which has a specific attribute
|
/<node>[@<attrib>=<value>]/<node> Find a node which has a specific attribute
|
||||||
*/
|
*/
|
||||||
int mxml_find_nodes1(PMXML_NODE tree, const char *xml_path, PMXML_NODE **nodelist, int *found)
|
|
||||||
{
|
{
|
||||||
PMXML_NODE pnode;
|
PMXML_NODE pnode;
|
||||||
const char *p1,*p2;
|
char *p1, *p2, *p3, node_name[256], condition[256];
|
||||||
char *p3, node_name[256], condition[256];
|
|
||||||
char cond_name[MXML_MAX_CONDITION][256], cond_value[MXML_MAX_CONDITION][256];
|
char cond_name[MXML_MAX_CONDITION][256], cond_value[MXML_MAX_CONDITION][256];
|
||||||
int cond_type[MXML_MAX_CONDITION];
|
int cond_type[MXML_MAX_CONDITION];
|
||||||
int i, j, k, index, num_cond;
|
int i, j, k, index, num_cond;
|
||||||
@ -819,7 +794,7 @@ int mxml_find_nodes1(PMXML_NODE tree, const char *xml_path, PMXML_NODE **nodelis
|
|||||||
p2++;
|
p2++;
|
||||||
} else {
|
} else {
|
||||||
/* evaluate [<@attrib>/<subnode>=<value>] */
|
/* evaluate [<@attrib>/<subnode>=<value>] */
|
||||||
while (*p2 && isspace((unsigned char)*p2))
|
while (*p2 && isspace(*p2))
|
||||||
p2++;
|
p2++;
|
||||||
strlcpy(condition, p2, sizeof(condition));
|
strlcpy(condition, p2, sizeof(condition));
|
||||||
if (strchr(condition, ']'))
|
if (strchr(condition, ']'))
|
||||||
@ -828,10 +803,12 @@ int mxml_find_nodes1(PMXML_NODE tree, const char *xml_path, PMXML_NODE **nodelis
|
|||||||
return 0;
|
return 0;
|
||||||
p2 = strchr(p2, ']')+1;
|
p2 = strchr(p2, ']')+1;
|
||||||
if ((p3 = strchr(condition, '=')) != NULL) {
|
if ((p3 = strchr(condition, '=')) != NULL) {
|
||||||
|
|
||||||
if (condition[0] == '@') {
|
if (condition[0] == '@') {
|
||||||
cond_type[num_cond] = 1;
|
cond_type[num_cond] = 1;
|
||||||
strlcpy(cond_name[num_cond], &condition[1], sizeof(cond_name[num_cond]));
|
strlcpy(cond_name[num_cond], &condition[1], sizeof(cond_name[num_cond]) - 1);
|
||||||
} else {
|
}
|
||||||
|
else {
|
||||||
strlcpy(cond_name[num_cond], condition, sizeof(cond_name[num_cond]));
|
strlcpy(cond_name[num_cond], condition, sizeof(cond_name[num_cond]));
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -914,7 +891,7 @@ int mxml_find_nodes1(PMXML_NODE tree, const char *xml_path, PMXML_NODE **nodelis
|
|||||||
|
|
||||||
/*------------------------------------------------------------------*/
|
/*------------------------------------------------------------------*/
|
||||||
|
|
||||||
int mxml_find_nodes(PMXML_NODE tree, const char *xml_path, PMXML_NODE **nodelist)
|
int mxml_find_nodes(PMXML_NODE tree, char *xml_path, PMXML_NODE **nodelist)
|
||||||
{
|
{
|
||||||
int status, found = 0;
|
int status, found = 0;
|
||||||
|
|
||||||
@ -928,11 +905,11 @@ int mxml_find_nodes(PMXML_NODE tree, const char *xml_path, PMXML_NODE **nodelist
|
|||||||
|
|
||||||
/*------------------------------------------------------------------*/
|
/*------------------------------------------------------------------*/
|
||||||
|
|
||||||
/**
|
PMXML_NODE mxml_find_node(PMXML_NODE tree, char *xml_path)
|
||||||
* Search for a specific XML node with a subset of XPATH specifications.
|
/*
|
||||||
* Return first found node. For syntax see mxml_find_nodes()
|
Search for a specific XML node with a subset of XPATH specifications.
|
||||||
*/
|
Return first found node. For syntax see mxml_find_nodes()
|
||||||
PMXML_NODE mxml_find_node(PMXML_NODE tree, const char *xml_path)
|
*/
|
||||||
{
|
{
|
||||||
PMXML_NODE *node, pnode;
|
PMXML_NODE *node, pnode;
|
||||||
int n;
|
int n;
|
||||||
@ -965,7 +942,7 @@ char *mxml_get_value(PMXML_NODE pnode)
|
|||||||
|
|
||||||
/*------------------------------------------------------------------*/
|
/*------------------------------------------------------------------*/
|
||||||
|
|
||||||
char *mxml_get_attribute(PMXML_NODE pnode, const char *name)
|
char *mxml_get_attribute(PMXML_NODE pnode, char *name)
|
||||||
{
|
{
|
||||||
int i;
|
int i;
|
||||||
|
|
||||||
@ -979,7 +956,7 @@ char *mxml_get_attribute(PMXML_NODE pnode, const char *name)
|
|||||||
|
|
||||||
/*------------------------------------------------------------------*/
|
/*------------------------------------------------------------------*/
|
||||||
|
|
||||||
int mxml_replace_node_name(PMXML_NODE pnode, const char *name)
|
int mxml_replace_node_name(PMXML_NODE pnode, char *name)
|
||||||
{
|
{
|
||||||
strlcpy(pnode->name, name, sizeof(pnode->name));
|
strlcpy(pnode->name, name, sizeof(pnode->name));
|
||||||
return TRUE;
|
return TRUE;
|
||||||
@ -987,7 +964,7 @@ int mxml_replace_node_name(PMXML_NODE pnode, const char *name)
|
|||||||
|
|
||||||
/*------------------------------------------------------------------*/
|
/*------------------------------------------------------------------*/
|
||||||
|
|
||||||
int mxml_replace_node_value(PMXML_NODE pnode, const char *value)
|
int mxml_replace_node_value(PMXML_NODE pnode, char *value)
|
||||||
{
|
{
|
||||||
if (pnode->value)
|
if (pnode->value)
|
||||||
pnode->value = (char *)realloc(pnode->value, strlen(value)+1);
|
pnode->value = (char *)realloc(pnode->value, strlen(value)+1);
|
||||||
@ -1004,7 +981,8 @@ int mxml_replace_node_value(PMXML_NODE pnode, const char *value)
|
|||||||
|
|
||||||
/*------------------------------------------------------------------*/
|
/*------------------------------------------------------------------*/
|
||||||
|
|
||||||
/**
|
int mxml_replace_subvalue(PMXML_NODE pnode, char *name, char *value)
|
||||||
|
/*
|
||||||
replace value os a subnode, like
|
replace value os a subnode, like
|
||||||
|
|
||||||
<parent>
|
<parent>
|
||||||
@ -1013,7 +991,6 @@ int mxml_replace_node_value(PMXML_NODE pnode, const char *value)
|
|||||||
|
|
||||||
if pnode=parent, and "name"="child", then "value" gets replaced
|
if pnode=parent, and "name"="child", then "value" gets replaced
|
||||||
*/
|
*/
|
||||||
int mxml_replace_subvalue(PMXML_NODE pnode, const char *name, const char *value)
|
|
||||||
{
|
{
|
||||||
int i;
|
int i;
|
||||||
|
|
||||||
@ -1029,10 +1006,8 @@ int mxml_replace_subvalue(PMXML_NODE pnode, const char *name, const char *value)
|
|||||||
|
|
||||||
/*------------------------------------------------------------------*/
|
/*------------------------------------------------------------------*/
|
||||||
|
|
||||||
/**
|
int mxml_replace_attribute_name(PMXML_NODE pnode, char *old_name, char *new_name)
|
||||||
* change the name of an attribute, keep its value
|
/* change the name of an attribute, keep its value */
|
||||||
*/
|
|
||||||
int mxml_replace_attribute_name(PMXML_NODE pnode, const char *old_name, const char *new_name)
|
|
||||||
{
|
{
|
||||||
int i;
|
int i;
|
||||||
|
|
||||||
@ -1049,10 +1024,8 @@ int mxml_replace_attribute_name(PMXML_NODE pnode, const char *old_name, const ch
|
|||||||
|
|
||||||
/*------------------------------------------------------------------*/
|
/*------------------------------------------------------------------*/
|
||||||
|
|
||||||
/**
|
int mxml_replace_attribute_value(PMXML_NODE pnode, char *attrib_name, char *attrib_value)
|
||||||
* change the value of an attribute
|
/* change the value of an attribute */
|
||||||
*/
|
|
||||||
int mxml_replace_attribute_value(PMXML_NODE pnode, const char *attrib_name, const char *attrib_value)
|
|
||||||
{
|
{
|
||||||
int i;
|
int i;
|
||||||
|
|
||||||
@ -1070,10 +1043,8 @@ int mxml_replace_attribute_value(PMXML_NODE pnode, const char *attrib_name, cons
|
|||||||
|
|
||||||
/*------------------------------------------------------------------*/
|
/*------------------------------------------------------------------*/
|
||||||
|
|
||||||
/**
|
|
||||||
* free memory of a node and remove it from the parent's child list
|
|
||||||
*/
|
|
||||||
int mxml_delete_node(PMXML_NODE pnode)
|
int mxml_delete_node(PMXML_NODE pnode)
|
||||||
|
/* free memory of a node and remove it from the parent's child list */
|
||||||
{
|
{
|
||||||
PMXML_NODE parent;
|
PMXML_NODE parent;
|
||||||
int i, j;
|
int i, j;
|
||||||
@ -1106,7 +1077,7 @@ int mxml_delete_node(PMXML_NODE pnode)
|
|||||||
|
|
||||||
/*------------------------------------------------------------------*/
|
/*------------------------------------------------------------------*/
|
||||||
|
|
||||||
int mxml_delete_attribute(PMXML_NODE pnode, const char *attrib_name)
|
int mxml_delete_attribute(PMXML_NODE pnode, char *attrib_name)
|
||||||
{
|
{
|
||||||
int i, j;
|
int i, j;
|
||||||
|
|
||||||
@ -1138,10 +1109,8 @@ int mxml_delete_attribute(PMXML_NODE pnode, const char *attrib_name)
|
|||||||
|
|
||||||
#define HERE root, file_name, line_number, error, error_size
|
#define HERE root, file_name, line_number, error, error_size
|
||||||
|
|
||||||
/**
|
PMXML_NODE read_error(PMXML_NODE root, char *file_name, int line_number, char *error, int error_size, char *format, ...)
|
||||||
* used inside mxml_parse_file for reporting errors
|
/* used inside mxml_parse_file for reporting errors */
|
||||||
*/
|
|
||||||
PMXML_NODE read_error(PMXML_NODE root, const char *file_name, int line_number, char *error, int error_size, char *format, ...)
|
|
||||||
{
|
{
|
||||||
char *msg, str[1000];
|
char *msg, str[1000];
|
||||||
va_list argptr;
|
va_list argptr;
|
||||||
@ -1166,20 +1135,18 @@ PMXML_NODE read_error(PMXML_NODE root, const char *file_name, int line_number, c
|
|||||||
|
|
||||||
/*------------------------------------------------------------------*/
|
/*------------------------------------------------------------------*/
|
||||||
|
|
||||||
/**
|
PMXML_NODE mxml_parse_buffer(char *buf, char *error, int error_size)
|
||||||
* Parse a XML buffer and convert it into a tree of MXML_NODE's.
|
/* parse a XML buffer and convert it into a tree of MXML_NODE's. Return NULL
|
||||||
* Return NULL in case of an error, return error description.
|
in case of an error, return error description. Optional file_name is used
|
||||||
* Optional file_name is used for error reporting if called from mxml_parse_file()
|
for error reporting if called from mxml_parse_file() */
|
||||||
*/
|
|
||||||
PMXML_NODE mxml_parse_buffer(const char *buf, char *error, int error_size)
|
|
||||||
{
|
{
|
||||||
char node_name[256], attrib_name[256], attrib_value[1000], quote;
|
char node_name[256], attrib_name[256], attrib_value[1000];
|
||||||
const char *p, *pv;
|
char *p, *pv;
|
||||||
int i,j, line_number;
|
int i,j, line_number;
|
||||||
PMXML_NODE root, ptree, pnew;
|
PMXML_NODE root, ptree, pnew;
|
||||||
int end_element;
|
int end_element;
|
||||||
size_t len;
|
size_t len;
|
||||||
char *file_name = NULL; /* dummy for 'HERE' */
|
char *file_name = NULL; // dummy for 'HERE'
|
||||||
|
|
||||||
p = buf;
|
p = buf;
|
||||||
line_number = 1;
|
line_number = 1;
|
||||||
@ -1282,7 +1249,7 @@ PMXML_NODE mxml_parse_buffer(const char *buf, char *error, int error_size)
|
|||||||
if (*p == '/') {
|
if (*p == '/') {
|
||||||
end_element = TRUE;
|
end_element = TRUE;
|
||||||
p++;
|
p++;
|
||||||
while (*p && isspace((unsigned char)*p)) {
|
while (*p && isspace(*p)) {
|
||||||
if (*p == '\n')
|
if (*p == '\n')
|
||||||
line_number++;
|
line_number++;
|
||||||
p++;
|
p++;
|
||||||
@ -1294,7 +1261,7 @@ PMXML_NODE mxml_parse_buffer(const char *buf, char *error, int error_size)
|
|||||||
/* extract node name */
|
/* extract node name */
|
||||||
i = 0;
|
i = 0;
|
||||||
node_name[i] = 0;
|
node_name[i] = 0;
|
||||||
while (*p && !isspace((unsigned char)*p) && *p != '/' && *p != '>' && *p != '<')
|
while (*p && !isspace(*p) && *p != '/' && *p != '>' && *p != '<')
|
||||||
node_name[i++] = *p++;
|
node_name[i++] = *p++;
|
||||||
node_name[i] = 0;
|
node_name[i] = 0;
|
||||||
if (!*p)
|
if (!*p)
|
||||||
@ -1324,7 +1291,7 @@ PMXML_NODE mxml_parse_buffer(const char *buf, char *error, int error_size)
|
|||||||
/* allocate new element structure in parent tree */
|
/* allocate new element structure in parent tree */
|
||||||
pnew = mxml_add_node(ptree, node_name, NULL);
|
pnew = mxml_add_node(ptree, node_name, NULL);
|
||||||
|
|
||||||
while (*p && isspace((unsigned char)*p)) {
|
while (*p && isspace(*p)) {
|
||||||
if (*p == '\n')
|
if (*p == '\n')
|
||||||
line_number++;
|
line_number++;
|
||||||
p++;
|
p++;
|
||||||
@ -1336,7 +1303,7 @@ PMXML_NODE mxml_parse_buffer(const char *buf, char *error, int error_size)
|
|||||||
|
|
||||||
/* found attribute */
|
/* found attribute */
|
||||||
pv = p;
|
pv = p;
|
||||||
while (*pv && !isspace((unsigned char)*pv) && *pv != '=' && *pv != '<' && *pv != '>')
|
while (*pv && !isspace(*pv) && *pv != '=' && *pv != '<' && *pv != '>')
|
||||||
pv++;
|
pv++;
|
||||||
if (!*pv)
|
if (!*pv)
|
||||||
return read_error(HERE, "Unexpected end of file");
|
return read_error(HERE, "Unexpected end of file");
|
||||||
@ -1351,7 +1318,7 @@ PMXML_NODE mxml_parse_buffer(const char *buf, char *error, int error_size)
|
|||||||
attrib_name[len] = 0;
|
attrib_name[len] = 0;
|
||||||
|
|
||||||
p = pv;
|
p = pv;
|
||||||
while (*p && isspace((unsigned char)*p)) {
|
while (*p && isspace(*p)) {
|
||||||
if (*p == '\n')
|
if (*p == '\n')
|
||||||
line_number++;
|
line_number++;
|
||||||
p++;
|
p++;
|
||||||
@ -1362,21 +1329,20 @@ PMXML_NODE mxml_parse_buffer(const char *buf, char *error, int error_size)
|
|||||||
return read_error(HERE, "Expect \"=\" here");
|
return read_error(HERE, "Expect \"=\" here");
|
||||||
|
|
||||||
p++;
|
p++;
|
||||||
while (*p && isspace((unsigned char)*p)) {
|
while (*p && isspace(*p)) {
|
||||||
if (*p == '\n')
|
if (*p == '\n')
|
||||||
line_number++;
|
line_number++;
|
||||||
p++;
|
p++;
|
||||||
}
|
}
|
||||||
if (!*p)
|
if (!*p)
|
||||||
return read_error(HERE, "Unexpected end of file");
|
return read_error(HERE, "Unexpected end of file");
|
||||||
if (*p != '\"' && *p != '\'')
|
if (*p != '\"')
|
||||||
return read_error(HERE, "Expect \" or \' here");
|
return read_error(HERE, "Expect \'\"\' here");
|
||||||
quote = *p;
|
|
||||||
p++;
|
p++;
|
||||||
|
|
||||||
/* extract attribute value */
|
/* extract attribute value */
|
||||||
pv = p;
|
pv = p;
|
||||||
while (*pv && *pv != quote)
|
while (*pv && *pv != '\"')
|
||||||
pv++;
|
pv++;
|
||||||
if (!*pv)
|
if (!*pv)
|
||||||
return read_error(HERE, "Unexpected end of file");
|
return read_error(HERE, "Unexpected end of file");
|
||||||
@ -1391,7 +1357,7 @@ PMXML_NODE mxml_parse_buffer(const char *buf, char *error, int error_size)
|
|||||||
mxml_add_attribute(pnew, attrib_name, attrib_value);
|
mxml_add_attribute(pnew, attrib_name, attrib_value);
|
||||||
|
|
||||||
p = pv+1;
|
p = pv+1;
|
||||||
while (*p && isspace((unsigned char)*p)) {
|
while (*p && isspace(*p)) {
|
||||||
if (*p == '\n')
|
if (*p == '\n')
|
||||||
line_number++;
|
line_number++;
|
||||||
p++;
|
p++;
|
||||||
@ -1405,7 +1371,7 @@ PMXML_NODE mxml_parse_buffer(const char *buf, char *error, int error_size)
|
|||||||
/* found empty node, like <node/>, just skip closing bracket */
|
/* found empty node, like <node/>, just skip closing bracket */
|
||||||
p++;
|
p++;
|
||||||
|
|
||||||
while (*p && isspace((unsigned char)*p)) {
|
while (*p && isspace(*p)) {
|
||||||
if (*p == '\n')
|
if (*p == '\n')
|
||||||
line_number++;
|
line_number++;
|
||||||
p++;
|
p++;
|
||||||
@ -1423,7 +1389,7 @@ PMXML_NODE mxml_parse_buffer(const char *buf, char *error, int error_size)
|
|||||||
|
|
||||||
/* check if we have sub-element or value */
|
/* check if we have sub-element or value */
|
||||||
pv = p;
|
pv = p;
|
||||||
while (*pv && isspace((unsigned char)*pv)) {
|
while (*pv && isspace(*pv)) {
|
||||||
if (*pv == '\n')
|
if (*pv == '\n')
|
||||||
line_number++;
|
line_number++;
|
||||||
pv++;
|
pv++;
|
||||||
@ -1475,12 +1441,10 @@ PMXML_NODE mxml_parse_buffer(const char *buf, char *error, int error_size)
|
|||||||
|
|
||||||
/*------------------------------------------------------------------*/
|
/*------------------------------------------------------------------*/
|
||||||
|
|
||||||
/**
|
int mxml_parse_entity(char **buf, char *file_name, char *error, int error_size)
|
||||||
* parse !ENTYTY entries of XML files and replace with references.
|
/* parse !ENTYTY entries of XML files and replace with references. Return 0
|
||||||
* Return 0 in case of no errors, return error description.
|
in case of no errors, return error description. Optional file_name is used
|
||||||
* Optional file_name is used for error reporting if called from mxml_parse_file()
|
for error reporting if called from mxml_parse_file() */
|
||||||
*/
|
|
||||||
int mxml_parse_entity(char **buf, const char *file_name, char *error, int error_size)
|
|
||||||
{
|
{
|
||||||
char *p;
|
char *p;
|
||||||
char *pv;
|
char *pv;
|
||||||
@ -1551,7 +1515,7 @@ int mxml_parse_entity(char **buf, const char *file_name, char *error, int error_
|
|||||||
|
|
||||||
/* found new entity */
|
/* found new entity */
|
||||||
p++;
|
p++;
|
||||||
while (*p && isspace((unsigned char)*p)) {
|
while (*p && isspace(*p)) {
|
||||||
if (*p == '\n')
|
if (*p == '\n')
|
||||||
line_number++;
|
line_number++;
|
||||||
p++;
|
p++;
|
||||||
@ -1601,7 +1565,7 @@ int mxml_parse_entity(char **buf, const char *file_name, char *error, int error_
|
|||||||
/* extract entity name */
|
/* extract entity name */
|
||||||
p = pv;
|
p = pv;
|
||||||
|
|
||||||
while (*p && isspace((unsigned char)*p) && *p != '<' && *p != '>') {
|
while (*p && isspace(*p) && *p != '<' && *p != '>') {
|
||||||
if (*p == '\n')
|
if (*p == '\n')
|
||||||
line_number++;
|
line_number++;
|
||||||
p++;
|
p++;
|
||||||
@ -1622,7 +1586,7 @@ int mxml_parse_entity(char **buf, const char *file_name, char *error, int error_
|
|||||||
}
|
}
|
||||||
|
|
||||||
pv = p;
|
pv = p;
|
||||||
while (*pv && !isspace((unsigned char)*pv) && *pv != '<' && *pv != '>')
|
while (*pv && !isspace(*pv) && *pv != '<' && *pv != '>')
|
||||||
pv++;
|
pv++;
|
||||||
|
|
||||||
if (!*pv) {
|
if (!*pv) {
|
||||||
@ -1645,7 +1609,7 @@ int mxml_parse_entity(char **buf, const char *file_name, char *error, int error_
|
|||||||
entity_name[nentity][0] = '&';
|
entity_name[nentity][0] = '&';
|
||||||
i = 1;
|
i = 1;
|
||||||
entity_name[nentity][i] = 0;
|
entity_name[nentity][i] = 0;
|
||||||
while (*p && !isspace((unsigned char)*p) && *p != '/' && *p != '>' && *p != '<' && i < 253)
|
while (*p && !isspace(*p) && *p != '/' && *p != '>' && *p != '<' && i < 253)
|
||||||
entity_name[nentity][i++] = *p++;
|
entity_name[nentity][i++] = *p++;
|
||||||
entity_name[nentity][i++] = ';';
|
entity_name[nentity][i++] = ';';
|
||||||
entity_name[nentity][i] = 0;
|
entity_name[nentity][i] = 0;
|
||||||
@ -1666,7 +1630,7 @@ int mxml_parse_entity(char **buf, const char *file_name, char *error, int error_
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* extract replacement or SYSTEM */
|
/* extract replacement or SYSTEM */
|
||||||
while (*p && isspace((unsigned char)*p)) {
|
while (*p && isspace(*p)) {
|
||||||
if (*p == '\n')
|
if (*p == '\n')
|
||||||
line_number++;
|
line_number++;
|
||||||
p++;
|
p++;
|
||||||
@ -1695,7 +1659,7 @@ int mxml_parse_entity(char **buf, const char *file_name, char *error, int error_
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* extract replacement */
|
/* extract replacement */
|
||||||
while (*p && isspace((unsigned char)*p)) {
|
while (*p && isspace(*p)) {
|
||||||
if (*p == '\n')
|
if (*p == '\n')
|
||||||
line_number++;
|
line_number++;
|
||||||
p++;
|
p++;
|
||||||
@ -1780,7 +1744,7 @@ int mxml_parse_entity(char **buf, const char *file_name, char *error, int error_
|
|||||||
free(replacement);
|
free(replacement);
|
||||||
|
|
||||||
p = pv;
|
p = pv;
|
||||||
while (*p && isspace((unsigned char)*p)) {
|
while (*p && isspace(*p)) {
|
||||||
if (*p == '\n')
|
if (*p == '\n')
|
||||||
line_number++;
|
line_number++;
|
||||||
p++;
|
p++;
|
||||||
@ -1920,11 +1884,9 @@ int mxml_parse_entity(char **buf, const char *file_name, char *error, int error_
|
|||||||
|
|
||||||
/*------------------------------------------------------------------*/
|
/*------------------------------------------------------------------*/
|
||||||
|
|
||||||
/**
|
PMXML_NODE mxml_parse_file(char *file_name, char *error, int error_size)
|
||||||
* parse a XML file and convert it into a tree of MXML_NODE's.
|
/* parse a XML file and convert it into a tree of MXML_NODE's. Return NULL
|
||||||
* Return NULL in case of an error, return error description
|
in case of an error, return error description */
|
||||||
*/
|
|
||||||
PMXML_NODE mxml_parse_file(const char *file_name, char *error, int error_size)
|
|
||||||
{
|
{
|
||||||
char *buf, line[1000];
|
char *buf, line[1000];
|
||||||
int fh, length;
|
int fh, length;
|
||||||
@ -1972,10 +1934,8 @@ PMXML_NODE mxml_parse_file(const char *file_name, char *error, int error_size)
|
|||||||
|
|
||||||
/*------------------------------------------------------------------*/
|
/*------------------------------------------------------------------*/
|
||||||
|
|
||||||
/**
|
|
||||||
* write complete subtree recursively into file opened with mxml_open_document()
|
|
||||||
*/
|
|
||||||
int mxml_write_subtree(MXML_WRITER *writer, PMXML_NODE tree, int indent)
|
int mxml_write_subtree(MXML_WRITER *writer, PMXML_NODE tree, int indent)
|
||||||
|
/* write complete subtree recursively into file opened with mxml_open_document() */
|
||||||
{
|
{
|
||||||
int i;
|
int i;
|
||||||
|
|
||||||
@ -1997,10 +1957,8 @@ int mxml_write_subtree(MXML_WRITER *writer, PMXML_NODE tree, int indent)
|
|||||||
|
|
||||||
/*------------------------------------------------------------------*/
|
/*------------------------------------------------------------------*/
|
||||||
|
|
||||||
/**
|
int mxml_write_tree(char *file_name, PMXML_NODE tree)
|
||||||
* write a complete XML tree to a file
|
/* write a complete XML tree to a file */
|
||||||
*/
|
|
||||||
int mxml_write_tree(const char *file_name, PMXML_NODE tree)
|
|
||||||
{
|
{
|
||||||
MXML_WRITER *writer;
|
MXML_WRITER *writer;
|
||||||
int i;
|
int i;
|
||||||
@ -2011,7 +1969,7 @@ int mxml_write_tree(const char *file_name, PMXML_NODE tree)
|
|||||||
return FALSE;
|
return FALSE;
|
||||||
|
|
||||||
for (i=0 ; i<tree->n_children ; i++)
|
for (i=0 ; i<tree->n_children ; i++)
|
||||||
if (tree->child[i].node_type == ELEMENT_NODE) /* skip PI and comments */
|
if (tree->child[i].node_type == ELEMENT_NODE) // skip PI and comments
|
||||||
if (!mxml_write_subtree(writer, &tree->child[i], TRUE))
|
if (!mxml_write_subtree(writer, &tree->child[i], TRUE))
|
||||||
return FALSE;
|
return FALSE;
|
||||||
|
|
||||||
@ -2051,10 +2009,8 @@ PMXML_NODE mxml_clone_tree(PMXML_NODE tree)
|
|||||||
|
|
||||||
/*------------------------------------------------------------------*/
|
/*------------------------------------------------------------------*/
|
||||||
|
|
||||||
/**
|
|
||||||
* print XML tree for debugging
|
|
||||||
*/
|
|
||||||
void mxml_debug_tree(PMXML_NODE tree, int level)
|
void mxml_debug_tree(PMXML_NODE tree, int level)
|
||||||
|
/* print XML tree for debugging */
|
||||||
{
|
{
|
||||||
int i, j;
|
int i, j;
|
||||||
|
|
||||||
@ -2094,11 +2050,9 @@ void mxml_debug_tree(PMXML_NODE tree, int level)
|
|||||||
|
|
||||||
/*------------------------------------------------------------------*/
|
/*------------------------------------------------------------------*/
|
||||||
|
|
||||||
/**
|
|
||||||
* free memory of XML tree, must be called after any
|
|
||||||
* mxml_create_root_node() or mxml_parse_file()
|
|
||||||
*/
|
|
||||||
void mxml_free_tree(PMXML_NODE tree)
|
void mxml_free_tree(PMXML_NODE tree)
|
||||||
|
/* free memory of XML tree, must be called after any
|
||||||
|
mxml_create_root_node() or mxml_parse_file() */
|
||||||
{
|
{
|
||||||
int i;
|
int i;
|
||||||
|
|
||||||
@ -2152,8 +2106,7 @@ void mxml_test()
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
/*------------------------------------------------------------------*/
|
/*------------------------------------------------------------------*/
|
||||||
/**
|
/* mxml_basename deletes any prefix ending with the last slash '/' character
|
||||||
mxml_basename deletes any prefix ending with the last slash '/' character
|
|
||||||
present in path. mxml_dirname deletes the filename portion, beginning with
|
present in path. mxml_dirname deletes the filename portion, beginning with
|
||||||
the last slash '/' character to the end of path. Followings are examples
|
the last slash '/' character to the end of path. Followings are examples
|
||||||
from these functions
|
from these functions
|
||||||
@ -2166,8 +2119,7 @@ void mxml_test()
|
|||||||
"path/to/test.txt" "path/to" "test.txt"
|
"path/to/test.txt" "path/to" "test.txt"
|
||||||
"test.txt "." "test.txt"
|
"test.txt "." "test.txt"
|
||||||
|
|
||||||
Under Windows, '\\' and ':' are recognized ad separator too.
|
Under Windows, '\\' and ':' are recognized ad separator too. */
|
||||||
*/
|
|
||||||
|
|
||||||
void mxml_basename(char *path)
|
void mxml_basename(char *path)
|
||||||
{
|
{
|
||||||
|
|||||||
42
mxml.h
42
mxml.h
@ -73,50 +73,52 @@ extern "C" {
|
|||||||
#endif
|
#endif
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
void mxml_suppress_date(int suppress);
|
||||||
MXML_WRITER *mxml_open_file(const char *file_name);
|
MXML_WRITER *mxml_open_file(const char *file_name);
|
||||||
MXML_WRITER *mxml_open_buffer(void);
|
MXML_WRITER *mxml_open_buffer(void);
|
||||||
int mxml_set_translate(MXML_WRITER *writer, int flag);
|
int mxml_set_translate(MXML_WRITER *writer, int flag);
|
||||||
int mxml_start_element(MXML_WRITER *writer, const char *name);
|
int mxml_start_element(MXML_WRITER *writer, const char *name);
|
||||||
int mxml_start_element_noindent(MXML_WRITER *writer, const char *name);
|
int mxml_start_element_noindent(MXML_WRITER *writer, const char *name);
|
||||||
int mxml_end_element(MXML_WRITER *writer);
|
int mxml_end_element(MXML_WRITER *writer);
|
||||||
int mxml_write_comment(MXML_WRITER *writer, const char *string);
|
int mxml_write_comment(MXML_WRITER *writer, const char *string);
|
||||||
int mxml_write_attribute(MXML_WRITER *writer, const char *name, const char *value);
|
int mxml_write_attribute(MXML_WRITER *writer, const char *name, const char *value);
|
||||||
int mxml_write_value(MXML_WRITER *writer, const char *value);
|
int mxml_write_value(MXML_WRITER *writer, const char *value);
|
||||||
|
int mxml_write_empty_line(MXML_WRITER *writer);
|
||||||
char *mxml_close_buffer(MXML_WRITER *writer);
|
char *mxml_close_buffer(MXML_WRITER *writer);
|
||||||
int mxml_close_file(MXML_WRITER *writer);
|
int mxml_close_file(MXML_WRITER *writer);
|
||||||
|
|
||||||
int mxml_get_number_of_children(PMXML_NODE pnode);
|
int mxml_get_number_of_children(PMXML_NODE pnode);
|
||||||
PMXML_NODE mxml_subnode(PMXML_NODE pnode, int index);
|
PMXML_NODE mxml_subnode(PMXML_NODE pnode, int index);
|
||||||
PMXML_NODE mxml_find_node(PMXML_NODE tree, const char *xml_path);
|
PMXML_NODE mxml_find_node(PMXML_NODE tree, char *xml_path);
|
||||||
int mxml_find_nodes(PMXML_NODE tree, const char *xml_path, PMXML_NODE **nodelist);
|
int mxml_find_nodes(PMXML_NODE tree, char *xml_path, PMXML_NODE **nodelist);
|
||||||
char *mxml_get_name(PMXML_NODE pnode);
|
char *mxml_get_name(PMXML_NODE pnode);
|
||||||
char *mxml_get_value(PMXML_NODE pnode);
|
char *mxml_get_value(PMXML_NODE pnode);
|
||||||
char *mxml_get_attribute(PMXML_NODE pnode, const char *name);
|
char *mxml_get_attribute(PMXML_NODE pnode, char *name);
|
||||||
|
|
||||||
int mxml_add_attribute(PMXML_NODE pnode, const char *attrib_name, const char *attrib_value);
|
int mxml_add_attribute(PMXML_NODE pnode, char *attrib_name, char *attrib_value);
|
||||||
PMXML_NODE mxml_add_special_node(PMXML_NODE parent, int node_type, const char *node_name, const char *value);
|
PMXML_NODE mxml_add_special_node(PMXML_NODE parent, int node_type, char *node_name, char *value);
|
||||||
PMXML_NODE mxml_add_special_node_at(PMXML_NODE parent, int node_type, const char *node_name, const char *value, int index);
|
PMXML_NODE mxml_add_special_node_at(PMXML_NODE parent, int node_type, char *node_name, char *value, int index);
|
||||||
PMXML_NODE mxml_add_node(PMXML_NODE parent, const char *node_name, const char *value);
|
PMXML_NODE mxml_add_node(PMXML_NODE parent, char *node_name, char *value);
|
||||||
PMXML_NODE mxml_add_node_at(PMXML_NODE parent, const char *node_name, const char *value, int index);
|
PMXML_NODE mxml_add_node_at(PMXML_NODE parent, char *node_name, char *value, int index);
|
||||||
|
|
||||||
PMXML_NODE mxml_clone_tree(PMXML_NODE tree);
|
PMXML_NODE mxml_clone_tree(PMXML_NODE tree);
|
||||||
int mxml_add_tree(PMXML_NODE parent, PMXML_NODE tree);
|
int mxml_add_tree(PMXML_NODE parent, PMXML_NODE tree);
|
||||||
int mxml_add_tree_at(PMXML_NODE parent, PMXML_NODE tree, int index);
|
int mxml_add_tree_at(PMXML_NODE parent, PMXML_NODE tree, int index);
|
||||||
|
|
||||||
int mxml_replace_node_name(PMXML_NODE pnode, const char *new_name);
|
int mxml_replace_node_name(PMXML_NODE pnode, char *new_name);
|
||||||
int mxml_replace_node_value(PMXML_NODE pnode, const char *value);
|
int mxml_replace_node_value(PMXML_NODE pnode, char *value);
|
||||||
int mxml_replace_subvalue(PMXML_NODE pnode, const char *name, const char *value);
|
int mxml_replace_subvalue(PMXML_NODE pnode, char *name, char *value);
|
||||||
int mxml_replace_attribute_name(PMXML_NODE pnode, const char *old_name, const char *new_name);
|
int mxml_replace_attribute_name(PMXML_NODE pnode, char *old_name, char *new_name);
|
||||||
int mxml_replace_attribute_value(PMXML_NODE pnode, const char *attrib_name, const char *attrib_value);
|
int mxml_replace_attribute_value(PMXML_NODE pnode, char *attrib_name, char *attrib_value);
|
||||||
|
|
||||||
int mxml_delete_node(PMXML_NODE pnode);
|
int mxml_delete_node(PMXML_NODE pnode);
|
||||||
int mxml_delete_attribute(PMXML_NODE, const char *attrib_name);
|
int mxml_delete_attribute(PMXML_NODE, char *attrib_name);
|
||||||
|
|
||||||
PMXML_NODE mxml_create_root_node();
|
PMXML_NODE mxml_create_root_node();
|
||||||
PMXML_NODE mxml_parse_file(const char *file_name, char *error, int error_size);
|
PMXML_NODE mxml_parse_file(char *file_name, char *error, int error_size);
|
||||||
PMXML_NODE mxml_parse_buffer(const char *buffer, char *error, int error_size);
|
PMXML_NODE mxml_parse_buffer(char *buffer, char *error, int error_size);
|
||||||
int mxml_parse_entity(char **buf, const char* file_name, char *error, int error_size);
|
int mxml_parse_entity(char **buf, char* file_name, char *error, int error_size);
|
||||||
int mxml_write_tree(const char *file_name, PMXML_NODE tree);
|
int mxml_write_tree(char *file_name, PMXML_NODE tree);
|
||||||
void mxml_debug_tree(PMXML_NODE tree, int level);
|
void mxml_debug_tree(PMXML_NODE tree, int level);
|
||||||
void mxml_free_tree(PMXML_NODE tree);
|
void mxml_free_tree(PMXML_NODE tree);
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user