views:

170

answers:

0

I'm looking for a streaming xml pretty printer for C/C++ that's either self contained or that uses libxml2 or expat and has a BSD-ish license. I've searched a bit and not found one. It seems like something that would be generally useful. Am I missing an obvious tool that does this?

Background: I have a library that outputs xml without whitespace all on one line. In some cases I'd like to pretty print that output. 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), ... formatting options ...);
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.