I’m going to be writing a program which has some web services in it that use XML to pass data back and forth. The format of the XML is predefined – I can’t change it to suit my needs – but in code I can handle the data any way I want.
My question: Is it better for me to handle the data structure in code as an XML tree, or to write an equivalent data structure as an object in the language along with some utility functions for conversion to and from the XML?
I have some thoughts on the issue myself, but I don’t want to unintentionally bias anyone’s answers. This is a language-agnostic question, but if there’s any language considerations you have I’d like to hear it.
Edit: To clarify, the XML format itself is setup in a logical manner. The object in the language wouldn’t differ much from it. For example, it might look something like this (this is a poor example, but you get the gist I hope):
<car> <make>DATA</make> <model>DATA</model> <ownershipDates> <startDate>DATA</startDate> <endDate>DATA</endDate> </ownershipDates> </car>
Without context, it’s hard to say. But I’m guessing you’ll have an easier time working with a native data structure. If the XML schema ever changes or you’re required to work with a different format, you would have decoupled those those changes from the rest of your program.
So probably go with the latter option: ‘Write an equivalent data structure as an object in the language along with some utility functions for conversion to and from the XML.’