I would prefer the following syntax:
<?xml version="1.0" encoding="utf-8"?> <users> <user> <name first-name="David" last-name="Smith" /> <phone home-phone="0441 234443" /> <email private-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 think it looks better if you select items for things that can be repeated and can have subelements, and in other cases I would personally use attributes because they can save a lot of memory space. As the xdib command said:
An element may not have two attributes with the same name. In particular, if you use attributes, you cannot assign two phone attributes to a user.
This is why I prefer the syntax above. I decided to take an element for the name, but I have enough parameters for the last name as an attribute, and I think that in this case there are enough attributes, because nothing else should be nested under them. You can have multiple addresses, but each address can have one street and one city. This is how I choose.
source share