Well, it has finally happened. I am dreaming about defects in our code. Dream in code? Dog, I live dream-in-code every day.
Time for a familiar argument, a familiar decision. You have a blank slate. You must define some data transfer objects for your consumer based on some requirements. You provide an interface that takes in one of these data structures and returns an XML representation of that data structure.
And, for the sake of this discussion, you are using Java’s XMLStreamWriter as your XML framework (I know, I know, there are much more uber l33t ways, but this was the most straightforward and painless way for you in the time-frame you were given).
Simple. SIMPLE. Right?
By now, your nudge, your twitch, your instinct is to define an appendTo(XMLStreamWriter) method to each object, which either writes a simple tag or calls appendTo(XMLStreamWriter) on its constituents: