mirror of
https://gitea.psi.ch/ELOG/mxml.git
synced 2026-09-09 01:23:22 +00:00
handle several conditions like /AAA[x=1][y=2][@aa=3]/BBB
This commit is contained in:
parent
d51de8ab4b
commit
2bd4d06829
86
mxml.c
86
mxml.c
@ -723,8 +723,11 @@ int mxml_find_nodes1(PMXML_NODE tree, char *xml_path, PMXML_NODE **nodelist, int
|
|||||||
*/
|
*/
|
||||||
{
|
{
|
||||||
PMXML_NODE pnode;
|
PMXML_NODE pnode;
|
||||||
char *p1, *p2, *p3, node_name[256], condition[256], subnode[256], cond_attr[256], value[256];
|
char *p1, *p2, *p3, node_name[256], condition[256];
|
||||||
int i, j, index;
|
char cond_name[MXML_MAX_CONDITION][256], cond_value[MXML_MAX_CONDITION][256];
|
||||||
|
int cond_type[MXML_MAX_CONDITION];
|
||||||
|
int i, j, k, index, num_cond;
|
||||||
|
int cond_satisfied;
|
||||||
size_t len;
|
size_t len;
|
||||||
|
|
||||||
p1 = xml_path;
|
p1 = xml_path;
|
||||||
@ -745,8 +748,9 @@ int mxml_find_nodes1(PMXML_NODE tree, char *xml_path, PMXML_NODE **nodelist, int
|
|||||||
memcpy(node_name, p1, len);
|
memcpy(node_name, p1, len);
|
||||||
node_name[len] = 0;
|
node_name[len] = 0;
|
||||||
index = 0;
|
index = 0;
|
||||||
subnode[0] = cond_attr[0] = value[0] = 0;
|
num_cond = 0;
|
||||||
if (*p2 == '[') {
|
while (*p2 == '[') {
|
||||||
|
cond_name[num_cond][0] = cond_value[num_cond][0] = cond_type[num_cond] = 0;
|
||||||
p2++;
|
p2++;
|
||||||
if (isdigit(*p2)) {
|
if (isdigit(*p2)) {
|
||||||
/* evaluate [index] */
|
/* evaluate [index] */
|
||||||
@ -767,55 +771,59 @@ int mxml_find_nodes1(PMXML_NODE tree, char *xml_path, PMXML_NODE **nodelist, int
|
|||||||
p2 = strchr(p2, ']')+1;
|
p2 = strchr(p2, ']')+1;
|
||||||
if ((p3 = strchr(condition, '=')) != NULL) {
|
if ((p3 = strchr(condition, '=')) != NULL) {
|
||||||
|
|
||||||
if (condition[0] == '@') {
|
if (condition[0] == '@')
|
||||||
strlcpy(cond_attr, condition+1, sizeof(cond_attr));
|
cond_type[num_cond] = 1;
|
||||||
*strchr(cond_attr, '=') = 0;
|
|
||||||
while (cond_attr[0] && isspace(cond_attr[strlen(cond_attr)-1]))
|
strlcpy(cond_name[num_cond], condition, sizeof(cond_name[num_cond]));
|
||||||
cond_attr[strlen(cond_attr)-1] = 0;
|
*strchr(cond_name[num_cond], '=') = 0;
|
||||||
} else {
|
while (cond_name[num_cond][0] && isspace(cond_name[num_cond][strlen(cond_name[num_cond])-1]))
|
||||||
strlcpy(subnode, condition, sizeof(subnode));
|
cond_name[num_cond][strlen(cond_name[num_cond])-1] = 0;
|
||||||
*strchr(subnode, '=') = 0;
|
|
||||||
while (subnode[0] && isspace(subnode[strlen(subnode)-1]))
|
|
||||||
subnode[strlen(subnode)-1] = 0;
|
|
||||||
}
|
|
||||||
p3++;
|
p3++;
|
||||||
while (*p3 && isspace(*p3))
|
while (*p3 && isspace(*p3))
|
||||||
p3++;
|
p3++;
|
||||||
if (*p3 == '\"') {
|
if (*p3 == '\"') {
|
||||||
strlcpy(value, p3+1, sizeof(value));
|
strlcpy(cond_value[num_cond], p3+1, sizeof(cond_value[num_cond]));
|
||||||
while (value[0] && isspace(value[strlen(value)-1]))
|
while (cond_value[num_cond][0] && isspace(cond_value[num_cond][strlen(cond_value[num_cond])-1]))
|
||||||
value[strlen(value)-1] = 0;
|
cond_value[num_cond][strlen(cond_value[num_cond])-1] = 0;
|
||||||
if (value[0] && value[strlen(value)-1] == '\"')
|
if (cond_value[num_cond][0] && cond_value[num_cond][strlen(cond_value[num_cond])-1] == '\"')
|
||||||
value[strlen(value)-1] = 0;
|
cond_value[num_cond][strlen(cond_value[num_cond])-1] = 0;
|
||||||
} else if (*p3 == '\'') {
|
} else if (*p3 == '\'') {
|
||||||
strlcpy(value, p3+1, sizeof(value));
|
strlcpy(cond_value[num_cond], p3+1, sizeof(cond_value[num_cond]));
|
||||||
while (value[0] && isspace(value[strlen(value)-1]))
|
while (cond_value[num_cond][0] && isspace(cond_value[num_cond][strlen(cond_value[num_cond])-1]))
|
||||||
value[strlen(value)-1] = 0;
|
cond_value[num_cond][strlen(cond_value[num_cond])-1] = 0;
|
||||||
if (value[0] && value[strlen(value)-1] == '\'')
|
if (cond_value[num_cond][0] && cond_value[num_cond][strlen(cond_value[num_cond])-1] == '\'')
|
||||||
value[strlen(value)-1] = 0;
|
cond_value[num_cond][strlen(cond_value[num_cond])-1] = 0;
|
||||||
} else {
|
} else {
|
||||||
strlcpy(value, p3, sizeof(value));
|
strlcpy(cond_value[num_cond], p3, sizeof(cond_value[num_cond]));
|
||||||
while (value[0] && isspace(value[strlen(value)-1]))
|
while (cond_value[num_cond][0] && isspace(cond_value[num_cond][strlen(cond_value[num_cond])-1]))
|
||||||
value[strlen(value)-1] = 0;
|
cond_value[num_cond][strlen(cond_value[num_cond])-1] = 0;
|
||||||
}
|
}
|
||||||
|
num_cond++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
for (i=j=0 ; i<pnode->n_children ; i++) {
|
for (i=j=0 ; i<pnode->n_children ; i++) {
|
||||||
if (subnode[0]) {
|
if (num_cond) {
|
||||||
/* search subnode */
|
cond_satisfied = 0;
|
||||||
for (j=0 ; j<pnode->child[i].n_children ; j++)
|
for (k=0;k<num_cond;k++) {
|
||||||
if (strcmp(pnode->child[i].child[j].name, subnode) == 0)
|
if (cond_type[k]) {
|
||||||
if (strcmp(pnode->child[i].child[j].value, value) == 0)
|
|
||||||
if (!mxml_add_resultnode(pnode->child+i, p2, nodelist, found))
|
|
||||||
return 0;
|
|
||||||
|
|
||||||
} else if (cond_attr[0]) {
|
|
||||||
/* search node with attribute */
|
/* search node with attribute */
|
||||||
if (strcmp(pnode->child[i].name, node_name) == 0)
|
if (strcmp(pnode->child[i].name, node_name) == 0)
|
||||||
if (mxml_get_attribute(pnode->child+i, cond_attr) &&
|
if (mxml_get_attribute(pnode->child+i, cond_name[k]) &&
|
||||||
strcmp(mxml_get_attribute(pnode->child+i, cond_attr), value) == 0)
|
strcmp(mxml_get_attribute(pnode->child+i, cond_name[k]), cond_value[k]) == 0)
|
||||||
|
cond_satisfied++;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
/* search subnode */
|
||||||
|
for (j=0 ; j<pnode->child[i].n_children ; j++)
|
||||||
|
if (strcmp(pnode->child[i].child[j].name, cond_name[k]) == 0)
|
||||||
|
if (strcmp(pnode->child[i].child[j].value, cond_value[k]) == 0)
|
||||||
|
cond_satisfied++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (cond_satisfied==num_cond)
|
||||||
if (!mxml_add_resultnode(pnode->child+i, p2, nodelist, found))
|
if (!mxml_add_resultnode(pnode->child+i, p2, nodelist, found))
|
||||||
return 0;
|
return 0;
|
||||||
} else {
|
} else {
|
||||||
|
|||||||
4
mxml.h
4
mxml.h
@ -21,7 +21,9 @@
|
|||||||
|
|
||||||
#define INTERNAL_ENTITY 0
|
#define INTERNAL_ENTITY 0
|
||||||
#define EXTERNAL_ENTITY 1
|
#define EXTERNAL_ENTITY 1
|
||||||
#define MXML_MAX_ENTITY 1000
|
#define MXML_MAX_ENTITY 500
|
||||||
|
|
||||||
|
#define MXML_MAX_CONDITION 10
|
||||||
|
|
||||||
#ifdef _MSC_VER
|
#ifdef _MSC_VER
|
||||||
#define DIR_SEPARATOR '\\'
|
#define DIR_SEPARATOR '\\'
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user