libxml2

libxml2 is an XML parser library. Written in C, it provides bindings to C++, PHP5, Python, Pascal, Common Lisp, and other languages.

Originally developed for the GNOME project, libxml2 is now a general-purpose XML/HTML toolkit rather than a GNOME-specific dependency. It implements a DOM-like tree API, a SAX2 interface, XPath and XPointer evaluation, XInclude processing, and validation against RELAX NG and XSD schemas, among other features. Its companion project, libxslt, provides XSLT 1.0 processing.

libxml2 underlies a number of higher-level libraries in other languages, including PHP's built-in DOM and SimpleXML extensions (see DOM Reference), Python's lxml, and Ruby's Nokogiri.

LanguageC
OriginDeveloped for the GNOME project
BindingsC++, PHP, Python, Pascal, Common Lisp, and others
CapabilitiesDOM-like tree API, SAX2 interface, XPath/XPointer, XInclude, RELAX NG and XSD validation
Notable usersPHP's DOM/SimpleXML extensions, Python's lxml, Ruby's Nokogiri
LicenseMIT license

#include <libxml/parser.h>
#include <libxml/tree.h>
#include <stdio.h>

int main() {
    xmlDocPtr doc = xmlReadFile("books.xml", NULL, 0);
    xmlNodePtr root = xmlDocGetRootElement(doc);

    printf("Root element: %s\n", root->name);

    xmlFreeDoc(doc);
    xmlCleanupParser();
    return 0;
}