When creating a new xml file, how does one go about structuring the file correctly or the best possible way. By structure, which may not be the best word in this case, I mean how does one choose between making something an element or an attribute of an element. For example, if I create a Person.xml file which contains a list of Persons, is it better to do something like:
<Person> <FirstName>John</FirstName> <LastName>Doe</LastName> <Age>23</Age> </Person>
or is it better to do something like this or does it even matter?
<Person FirstName='John' LastName='Doe' Age='23'></Person>
XML files should (not to start a holy war) be structured as follows:
If it’s data, or something that can be changed, then it should be like this:
If it’s an attribute of the thing
Personthen it should be like this:There are multiple reasons for this practice, not the least of which includes the ease of fixing your XSLT Transforms whenever you change your method of retrieving Person data.
That’s really the important part: Attributes define information about data (the Person Type), and the Data is something that is meant to fill in those holes. If you decide how you’re going to change how you fill in those holes, then it becomes tougher if you’ve made them ‘attributes’ instead of ‘data’ when you want to Transform your XML later.