XML Attributes or Element Nodes?
Posted
by Camsoft
on Stack Overflow
See other posts from Stack Overflow
or by Camsoft
Published on 2010-03-18T10:48:01Z
Indexed on
2010/03/18
10:51 UTC
Read the original article
Hit count: 601
Example XML using element nodes:
<?xml version="1.0" encoding="utf-8"?>
<users>
<user>
<name>David Smith</name>
<phone>0441 234443</phone>
<email>[email protected]</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="[email protected]">
<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 relation database and can't work out whether I should use attributes or elements.
What is best practice when building XML files?
© Stack Overflow or respective owner