streaming xml pretty printer in C/C++ using expat or libxml2?
- by Mark Zeren
I have a library that outputs xml without whitespace all on one line. In some cases I'd like to pretty print that output. I'm looking for a BSD-ish licensed C/C++ library or sample code that will take a raw xml byte stream and pretty print it. Here's some pseudo code showing one way that I might use this functionality: 
void my_write(const char* buf, int len);
PrettyPrinter pp(bind(&my_write));
while (...) {
    // ... get some more xml ...
    const char* buf = xmlSource.get_buf();
    int len = xmlSource.get_buf_len();
    int written = pp.write(buf, len); // calls my_write with pretty printed xml
    // ... error handling, maybe call write again, etc. ...
}
I'd like to avoid instantiating a DOM representation. I already have dependencies on the expat and libxml2 shared libraries, and I'd rather not add any more shared library dependencies.