From time to time I create whole documents (e.g. XML or proprietary) programmatically.
If it easy enough, I just write something like
stringbuilder.append("<blah>");
stringbuilder.append("<blubb>");
stringbuilder.append(someValue);
stringbuilder.append("</blubb>");
stringbuilder.append("</blah>");
But what if the document schema gets more complex? How would one describe it? What if it is not well structured like XML, but has an arbitrary format?
Right now I thought about an abstract description of the format that just needs to get the blanks filled. What if I also have to parse such a document?
But this seems to be a recurring problem to me.
So: Is there some "pattern" to solve that?