I'm currently working on a website that imports XML data that we download from another companies ftp site. Its for an online store, so I'm downloading orders, items, item updates.. etc..
Now the XML file for the product listing looks like a monkey slapped it together. What I mean is, its not generic. Some products have fields that other products don't in the xml file.
For example one product might have the following...
<Value AttributeID="Color">Orange</Value>
<Value AttributeID="Quantity">1000</Value>
<Value AttributeID="Master Model Header">Air Soft Ammunition</Value>
<Value AttributeID="Master Model Body Copy">
While the next product will have...
<Value AttributeID="Caliber">.177</Value>
<Value AttributeID="Quantity per Box">600</Value>
<Value AttributeID="Master Model Header">Pegable Blister Box BBs</Value>
<Value AttributeID="Master Model Body Copy">
Obviously there are SOME similarities, but not every product is the same. This is my first REAL xml project and I'm not sure how to handle something like this.
I understand that not every product in a store as the same attributes, but even so, the products aren't categorized in the xml files so I have no way of determining the product "type" and that this product "type" has these specific "attributes" and even if they were categorized, there are thousands of products. I would have to generate a model for each type of product, which could mean thousands of models.
So ho开发者_运维问答w do I process these random attributes? How would you go about doing this?
Any DOM implementation should let you walk the tree and figure out what elements and attributes exist and what values they have.
From that you can build up a list of possible values for possible attributes and decide how you want them to map onto your own system.
Then just makes sure that when you import them, you check for new unknown attributes/values and have the system notify you for manual intervention (i.e. additional map functions).
精彩评论