I am setting up an XML file for a web site that I am creating. The XML file is to contain art (image) details. Each art record can have multiple sizes available (size1, size2, etc.) for purchase and multiple categories (cat1, cat2, cat3, etc). What is the best way to setup the xml file for multiple values? Here are the two options that I can think of.
…With elements for size and category…
<?xml version='1.0' encoding='utf-8' ?>
<images>
<image id='' ImageName=''>
<title></title>
<sizes>
<size>size1</size>
<size>size2</size>
</sizes>
<categories>
<category>cat1</category>
<category>cat2</category>
</categories>
<description>
<short></short>
<long></long>
</description>
</image>
</images>
with JQuery ajax, I reference each size / category with the following…
$(xml).find('image').each(function(){
$(this).find('size').each(function(){
var size = $(this).text();
{do something here with the size variable}
});
});
…OR…
…With attributes for size and category…
<?xml version='1.0' encoding='utf-8' ?>
<images>
<image id='' ImageName='' sizes='size1 size2' category='cat1 cat2 cat3'>
<title></title>
<description>
<short></short>
<long></long>
</description>
</image>
</images>
with JQuery ajax, I can reference each size / category with the following…
$(xml).find('image').each(function(){
$(this).attr('size').split(' ');
{Loop through each split attribute}
});
Any help is much appreciated.
I would take advantage of the intrinsic nature of xml to define and document the relationships in the data it marks up.
Use of elements for multiple values conceptually keeps the xml representation of your object closer to the model without requiring you have an understanding of the domain to interpret it.
It is clear here that there are two sizes.
A space inside a string has no intrinsic meaning in xml
This may be clear there are two size, but only because of your understanding of sizes.
Is this one bebos value of
sldkd eldksor two bebo values ofsldkdandeldks?But…
You would not want to return to a project a year later, or pick up somebody elses code, with the intention of adding or changing functionality and not realize you had to go through extra steps to make the pure data behave properly.