XML Attributes or Element Nodes?
data-structures, xml, xsd
Solution
One of the better articles I've read is "Principles of XML design: When to use elements versus attributes", which doesn't attempt to give you an outright answer but does give some good food for thought along with examples.
I would suggest that the advice in the article leans toward your first design; you may be interested to read the part about representing names though.
Problem
Example XML using element nodes: ``` <?xml version="1.0" encoding="utf-8"?> <users> <user> <name>David Smith</name> <phone>0441 234443</phone> <email>dave.s33@domain.com</email> <addresses> <address> <street>1 Some Street</street> <town>Toy Town</town> <country>UK</country> </address> <address> <street>5 New Street</street> <town>Lego City</town> <country>US</country> </address> </addresses> </user> </users> ``` Example XML using attributes: ``` <?xml version="1.0" encoding="utf-8"?> <users> <user name="David Smith" phone="0441 234443" email="dave.s33@domain.com"> <addresses> <address street="1 Some Street" town="Toy Town" country="UK" /> <address street="5 New Street" town="Lego City" country="US" /> </addresses> </user> </users> ``` I'm needing to build an XML file based on data from a relational database and can't work out whether I should use attributes or elements. What is best practice when building XML files and why?