Or if you prefer C++, simply use its C++ binding, libxml++.
I would certainly recommend using libxml++ above libxml2 directly.
Although libxml2 has very extensive capability, the memory management
in it is a a total nightmare. If you use it directly, forget about
good RAII practices. Various functions can return a pointer to memory
owned by another object that you shouldn't touch or memory that has
been allocated by this function and that you are responsible to free.
Freeing this memory is done via a function call but which function
call depend on what function allocated the object (xmlFree,
xmlFreeDoc, xsltFreeStylesheet, xmlXPathFreeObject, etc. etc). And
sometimes, the content of the allocated object contains pointers to
memory owned by another object. And don't forget to initialise your
library and clean up afterward with xmlCleanupParser(). Etc. etc.
To its credit, it works. So it might be worth using and is most
probably better than implementing your own xml parser from scratch. I
would just have liked it to use better (and more consistent) ownership
patterns.
Yan