mirror of
https://github.com/ivabus/pantry
synced 2024-11-14 12:35:10 +03:00
27 lines
666 B
C
27 lines
666 B
C
#include <stdio.h>
|
|
#include "expat.h"
|
|
static void XMLCALL my_StartElementHandler(
|
|
void *userdata,
|
|
const XML_Char *name,
|
|
const XML_Char **atts)
|
|
{
|
|
printf("tag:%s|", name);
|
|
}
|
|
static void XMLCALL my_CharacterDataHandler(
|
|
void *userdata,
|
|
const XML_Char *s,
|
|
int len)
|
|
{
|
|
printf("data:%.*s|", len, s);
|
|
}
|
|
int main()
|
|
{
|
|
static const char str[] = "<str>Hello, world!</str>";
|
|
int result;
|
|
XML_Parser parser = XML_ParserCreate("utf-8");
|
|
XML_SetElementHandler(parser, my_StartElementHandler, NULL);
|
|
XML_SetCharacterDataHandler(parser, my_CharacterDataHandler);
|
|
result = XML_Parse(parser, str, sizeof(str), 1);
|
|
XML_ParserFree(parser);
|
|
return result;
|
|
}
|