If you do not want to use a library, you will have to write it yourself. That should not be too hard. You will first have to tokenize the stream into tags and values. This is the hardest part I guess. Then you have to write the tokens to a stream. For every opening tag that follows an opening tag, you increase the indent, and for every closing tag that follows a closing tag you decrease the indent.
Some hints for the tokenizing. I think what I would try is to write a simple XMLToken class like this:
class XMLToken {
public:
enum ElementType { OpenTag, CloseTag, Value };
std::string content;
ElementType elementType;
};
These members should be encapsulated with appropriate getters and setters, this is just for illustration. Then I would overload the stream extraction operator for this type:
std::istream & operator >>(st::istream & stream, XMLToken & token) {
// if first char is '<', then token is a tag, otherwise a value
// read until '>' is found for a tag and until '<' is found for a value
return stream;
}
Then you can use an istream_iterator
for tokenizing the stream:
typedef std::istream_iterator< XMLToken > XMLTokenizer;
for ( XMLTokenizer it = XMLTokenizer(some_istream); it != XMLTokenizer; it++ ) {
// process token
}
Hope this helps you a bit.