私が作成しているWebサイト用のXMLファイルを設定しています。 XMLファイルには、アート(画像)の詳細が含まれます。各アートレコードは、購入可能な複数のサイズ(size1、size2など)と複数のカテゴリ(cat1、cat2、cat3など)を持つことができます。 xmlファイルを複数の値に設定する最良の方法は何ですか?ここに私が考えることができる2つのオプションがあります。 jQueryのアヤックスとXMLファイルを設定する - 複数の値に対してattrまたは要素を使用する
サイズとカテゴリの要素を持つ... ...
<?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>
、私は、次の各サイズ/カテゴリを参照...
$(xml).find('image').each(function(){
$(this).find('size').each(function(){
var size = $(this).text();
{do something here with the size variable}
});
});
... OR ...
サイズとカテゴリの属性を持つ
... ... jQueryのアヤックスと
<?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>
、私は、次の各サイズ/カテゴリを参照することができます...
$(xml).find('image').each(function(){
$(this).attr('size').split(' ');
{Loop through each split attribute}
});
どれでも助けをたくさんいただきました。
要素で別のオプションがあります... ' ' –