#include
int main()
{
mxml_node_t *tree; /* */
mxml_node_t *data; /* */
mxml_node_t *node; /*
mxml_node_t *group; /*
mxml_type_t type;
int white = 1;
char * p = NULL;
FILE *fp;
fp = fopen("filename.xml", "r+");
tree = mxmlLoadFile(NULL, fp,
MXML_TEXT_CALLBACK);
printf("tree = %p\n", tree);
data = mxmlFindElement(tree, tree, "data",
NULL, NULL,
MXML_DESCEND);
printf("data = %p\n", node);
node = mxmlFindElement(data, tree, "node",
NULL, NULL,
MXML_DESCEND);
printf("node = %p\n", node);
p = mxmlGetText(node, &white);
printf("p = %s\n", p);
node = mxmlFindElement(node, tree, "node",
NULL, NULL,
MXML_DESCEND);
printf("node = %p\n", node);
p = mxmlGetText(node, &white);
printf("p = %s\n", p);
int ret = mxmlSetText(node, white, "value");
printf("ret = %d\n", ret);
p = mxmlGetText(node, &white);
printf("p = %s\n", p);
fseek ( fp , 0 , SEEK_SET );
mxmlSaveFile(tree, fp, MXML_NO_CALLBACK);
mxmlDelete(tree);
tree = NULL;
fclose(fp);
return 0;
}
增加一个整型数据
#include
void main()
{
mxml_node_t *xml; /* */
mxml_node_t *data; /* */
mxml_node_t *node; /*
mxml_node_t *group; /*
xml = mxmlNewXML("1.0");
data = mxmlNewElement(xml, "data");
node = mxmlNewElement(data, "node");
mxmlNewText(node, 0, "val1");
node = mxmlNewElement(data, "node");
mxmlNewInteger(node, 5);
//
node = mxmlNewElement(data, "node");
mxmlNewText(node, 0, "val2");
node = mxmlNewElement(data, "node");
mxmlNewText(node, 0, "val3");
group = mxmlNewElement(data, "group");
node = mxmlNewElement(group, "node");
mxmlNewText(node, 0, "val4");
node = mxmlNewElement(group, "node");
mxmlNewText(node, 0, "val5");
node = mxmlNewElement(group, "node");
mxmlNewText(node, 0, "val6");
node = mxmlNewElement(data, "node");
mxmlNewText(node, 0, "val7");
node = mxmlNewElement(data, "node");
mxmlNewText(node, 0, "val8");
FILE *fp;
//mxml_node_t *tree;
fp = fopen("filename.xml", "w");
mxmlSaveFile(xml, fp, MXML_NO_CALLBACK);
fclose(fp);
return ;
}
gcc -o xml xml.c -lmxl -lpthread