0

私は eBay Trading API を使用しており、API 呼び出しの 1 つの一部が XML 要素の ItemSpecifics 配列で返されます。簡単な例を以下に示します。

<ItemSpecifics>
<NameValueList>
    <Name>Brand</Name>
    <Value>My1stWish</Value>
    <Source>ItemSpecific</Source>
</NameValueList>
</ItemSpecifics>

したがって、属性NameValueが返されます。

すべてのアイテムが同じ名前属性のセットで戻ってくるわけではありません。一部の eBay リストには何もない場合もあれば、20 がある場合もあり、それらの 20 は次のリストとは完全に異なり、15 の異なる属性があります。

私の質問は次のとおりです。これらの属性値をMySQLデータベーステーブルに保存し、そのテーブルから引き出せるように、これらの属性 値をどのように処理することをお勧めしますか?ヘッダーと対応する?

これらをシリアル化されたデータとして「ItemSpecifics」という列のテーブルにダンプする必要がありますか? しかし、CSVファイルなどの見出しとしてすべてのオプションを含むフラットファイルを作成できるように、それらを再度取得する方法がわかりません。

以下の 2 つの例:

リスト 1 は以下を返します。

<ItemSpecifics>
<NameValueList>
    <Name>Brand</Name>
    <Value>My1stWish</Value>
    <Source>ItemSpecific</Source>
</NameValueList>
<NameValueList>
    <Name>Exact Colour</Name>
    <Value>Black</Value>
    <Source>ItemSpecific</Source>
</NameValueList>
</ItemSpecifics>

リスト 2 は以下を返します。

<ItemSpecifics>
<NameValueList>
    <Name>Exact Heel Height</Name>
    <Value>4.1"</Value>
    <Source>ItemSpecific</Source>
</NameValueList>
<NameValueList>
    <Name>Heel Type</Name>
    <Value>Stiletto</Value>
    <Source>ItemSpecific</Source>
</NameValueList>
</ItemSpecifics>
4

1 に答える 1

0

There's a couple of way to do it that I can think of. First, as you mentioned, there's serialization. That's where you would dump your data into an array, run it through serialize and stick it in the same row as your other data.

The second way is probably better, however. That is, you make a table that is relational to your items. Let's say you have a table called items. In it, you make an automatic ID (auto-increment) field called item_id. So you pull your item data out and put it into this table. We'll say that it gets an ID of 20. Now, you have a second table called item_options. Inside this table, you would store your options, row by row. You would also put in the ID of the parent row. So let's say you have 5 sets of options. You would have five rows, each with that item_id of 20. The advantage here is that your data is now fully expanded so you could, for instance, query your options table to find all products that offer the color red. This is the "relational database" part of RDBMS.

于 2013-10-25T00:12:32.297 に答える