MENU
Expat
Expat is a parser library written in C. It is stream-oriented, open-source, and used in the Apache HTTP Server, Mozilla, Perl, Python, and PHP, among many other languages and applications.Expat is a non-validating, event-driven parser in the style of SAX: it reports parsing events, such as element starts and ends and character data, to application-registered callback (handler) functions as it streams through the document, without checking the document against a DTD or other schema beyond well-formedness. Originally written by James Clark, it is maintained today as libexpat and distributed under the MIT license.
Because it is a small, portable C library, Expat is commonly embedded in other languages via bindings, such as Python's xml.parsers.expat module and PHP's ext/xml extension, rather than used directly by application code.
| Language | C |
| Processing model | Stream-oriented, event-driven (SAX-style) |
| Validation | Non-validating; checks well-formedness only |
| License | Open source (MIT license) |
| Notable users | Apache HTTP Server, Mozilla, Perl, Python, PHP, and others |
#include <expat.h>
#include <stdio.h>
static void startElement(void *data, const char *name, const char **attr) {
printf("<%s>\n", name);
}
static void endElement(void *data, const char *name) {
printf("</%s>\n", name);
}
int main() {
XML_Parser parser = XML_ParserCreate(NULL);
XML_SetElementHandler(parser, startElement, endElement);
/* XML_Parse(parser, buffer, length, isFinal); */
XML_ParserFree(parser);
return 0;
}