Looking for streaming xml pretty printer in C/C++ using expat or libxml2
- by Mark Zeren
I'm looking for a streaming xml pretty printer for C/C++ that's either self contained or that uses libxml2 or expat. 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. 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.