]>
git.saurik.com Git - wxWidgets.git/blob - src/expat/examples/elements.c
1 /* This is simple demonstration of how to use expat. This program
2 reads an XML document from standard input and writes a line with
3 the name of each element to standard output indenting child
4 elements by one tab stop more than their parent element.
5 It must be used with Expat compiled for UTF-8 output.
11 #if defined(__amigaos__) && defined(__USE_INLINE__)
12 #include <proto/expat.h>
16 #if defined(XML_USE_MSC_EXTENSIONS) && _MSC_VER < 1400
17 #define XML_FMT_INT_MOD "I64"
19 #define XML_FMT_INT_MOD "ll"
22 #define XML_FMT_INT_MOD "l"
26 startElement(void *userData
, const char *name
, const char **atts
)
29 int *depthPtr
= (int *)userData
;
30 for (i
= 0; i
< *depthPtr
; i
++)
37 endElement(void *userData
, const char *name
)
39 int *depthPtr
= (int *)userData
;
44 main(int argc
, char *argv
[])
47 XML_Parser parser
= XML_ParserCreate(NULL
);
50 XML_SetUserData(parser
, &depth
);
51 XML_SetElementHandler(parser
, startElement
, endElement
);
53 int len
= (int)fread(buf
, 1, sizeof(buf
), stdin
);
54 done
= len
< sizeof(buf
);
55 if (XML_Parse(parser
, buf
, len
, done
) == XML_STATUS_ERROR
) {
57 "%s at line %" XML_FMT_INT_MOD
"u\n",
58 XML_ErrorString(XML_GetErrorCode(parser
)),
59 XML_GetCurrentLineNumber(parser
));
63 XML_ParserFree(parser
);