]>
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.
11 startElement(void *userData
, const char *name
, const char **atts
)
14 int *depthPtr
= userData
;
15 for (i
= 0; i
< *depthPtr
; i
++)
22 endElement(void *userData
, const char *name
)
24 int *depthPtr
= userData
;
29 main(int argc
, char *argv
[])
32 XML_Parser parser
= XML_ParserCreate(NULL
);
35 XML_SetUserData(parser
, &depth
);
36 XML_SetElementHandler(parser
, startElement
, endElement
);
38 size_t len
= fread(buf
, 1, sizeof(buf
), stdin
);
39 done
= len
< sizeof(buf
);
40 if (XML_Parse(parser
, buf
, len
, done
) == XML_STATUS_ERROR
) {
43 XML_ErrorString(XML_GetErrorCode(parser
)),
44 XML_GetCurrentLineNumber(parser
));
48 XML_ParserFree(parser
);