I am currently working on an XML document that was written for an XML hierarchy with only 2 levels. Right now, I want to add a one-to-many categorization to it that would break most of the code that works with that file.
I could either add that categorization as a new level, or I can implement it as a attribute on the same level (almost like tagging).
current:
<category>
<subcategory></subcategory>
<category>
proposed:
<supercategory>
<category>
<subcategory></subcategory>
</category>
</supercategory>
or:
<category supercategory="">
<subcategory></subcategory>
</category>
Which method is more maintainable?
To me, one of the strengths of XML is that the hierarchical nature of XML elements is ideally suited to describing hierarchical arrangements of objects, such as in your case. As such, I tend to prefer your first option, as your XML structure more resembles the structure of your data. This makes it much easier to read, manage and understand, IMHO.
That said, only you can really say if the extra effort required to make it work with your existing codebase is worth it. There's certainly nothing stopping doing it your second way if you think the required modifications are too difficult/time consuming, I just don't think it is as elegant a solution.