#include "ezxml.h"
#define MULTI_LINE_STRING(a) #a
/* --------------------------------------------------------------------------*/
/**
* Given the following example XML document:
*
*
*
*
*
* Kimi Raikkonen
* 112
*
*
* Juan Pablo Montoya
* 60
*
*
*
*/
/* ----------------------------------------------------------------------------*/
/* --------------------------------------------------------------------------*/
/**
* @brief ezxml_example_1
*/
/* ----------------------------------------------------------------------------*/
#include "fs.h"
#define XML_FILE_NAME SDFILE_RES_ROOT_PATH"ezxml.xml"
void ezxml_example_1(void)
{
printf("%s", __FUNCTION__);
ezxml_t f1 = ezxml_parse_file(XML_FILE_NAME), team, driver;
const char *teamname;
for (team = ezxml_child(f1, "team"); team; team = team->next) {
teamname = ezxml_attr(team, "name");
for (driver = ezxml_child(team, "driver"); driver; driver = driver->next) {
printf("%s, %s: %s\n", ezxml_child(driver, "name")->txt, teamname,
ezxml_child(driver, "points")->txt);
}
}
ezxml_free(f1);
}
/* --------------------------------------------------------------------------*/
/**
* @brief ezxml_example_2
*/
/* ----------------------------------------------------------------------------*/
// *INDENT-OFF*
static const char *xml_msg= MULTI_LINE_STRING(
);
// *INDENT-ON*
void ezxml_example_2(void)
{
ezxml_t f1, msg;
printf("%s", __FUNCTION__);
char *buf = malloc(strlen(xml_msg));
memcpy(buf, xml_msg, strlen(xml_msg));
f1 = ezxml_parse_str(buf, strlen(xml_msg));
msg = ezxml_child(f1, "msg");
for (msg = ezxml_child(f1, "msg"); msg; msg = msg->next) {
printf("handle:%s, subject:%s, datetime:%s, size:%s", ezxml_attr(msg, "handle"), ezxml_attr(msg, "subject"), ezxml_attr(msg, "datetime"), ezxml_attr(msg, "size"));
}
ezxml_free(f1);
free(buf);
}
/* --------------------------------------------------------------------------*/
/**
* @brief ezxml_example_3
*/
/* ----------------------------------------------------------------------------*/
// *INDENT-OFF*
static const char *xml_str = MULTI_LINE_STRING(
Kimi Raikkonen
112
Juan Pablo Montoya
60
);
// *INDENT-ON*
void ezxml_example_3(void)
{
ezxml_t f1, team, driver;
const char *teamname;
printf("%s", __FUNCTION__);
char *buf = malloc(strlen(xml_str));
memcpy(buf, xml_str, strlen(xml_str));
f1 = ezxml_parse_str(buf, strlen(xml_str));
for (team = ezxml_child(f1, "team"); team; team = team->next) {
teamname = ezxml_attr(team, "name");
for (driver = ezxml_child(team, "driver"); driver; driver = driver->next) {
printf("%s, %s: %s\n", ezxml_child(driver, "name")->txt, teamname,
ezxml_child(driver, "points")->txt);
}
}
ezxml_free(f1);
free(buf);
}