You are here:  » Strange Goings On!!


Strange Goings On!!

Submitted by mark_79_smith on Tue, 2005-12-13 22:29 in

Firstly I want to say that this script is much better than what I've found searching on Google.

I basically have a stock list of my suppliers product which I sell. The XML format looks like this:
<CATEGORY id='67' name='Category Name'>
<PRODUCT ITEM="3185">
<NAME>XXX</NAME>
<MODEL>7217</MODEL>
<PRICE>1.65</PRICE>
<RRP>4.75</RRP>
<THUMB>7217s.jpg</THUMB>
<IMAGE>7217.jpg</IMAGE>
<DESCRIPTION>XXXX</DESCRIPTION>
<POWER>1 x AA (Included)</POWER>
<SIZE>XXX</SIZE>
<ATTRIBUTES NAME="Batteries">
<ATTRIBUTEVALUES VALUE="190" TITLE="None" />
<ATTRIBUTEVALUES VALUE="185" TITLE="1 x AA" />
</ATTRIBUTES>
</PRODUCT>
<PRODUCT ITEM="3186">
<NAME>XXX</NAME>
<MODEL>7217</MODEL>
<PRICE>1.65</PRICE>
<RRP>4.75</RRP>
<THUMB>7218s.jpg</THUMB>
<IMAGE>7218.jpg</IMAGE>
<DESCRIPTION>XXXX</DESCRIPTION>
<POWER>1 x AA (Included)</POWER>
<SIZE>XXX</SIZE>
<ATTRIBUTES NAME="Batteries">
<ATTRIBUTEVALUES VALUE="190" TITLE="None" />
<ATTRIBUTEVALUES VALUE="185" TITLE="1 x AA" />
</ATTRIBUTES>
</PRODUCT>
</CATEGORY>

The problem I have is 2 fold:
1. If I want the Category in the array only 1 product will show in the array for that category.
2. If I get rid of the Category option, I get all products but any arrays that branch off the product will only show the last option. For example in the above code 'None' will not show, but '1 x AA' will.

Is there a fix for this?

Submitted by support on Tue, 2005-12-13 23:53

Hi,

This is the same issue being referred to in this thread:
http://www.magicparser.com/node/44

However, the work-around described there would not work in the context of the above XML block.

As you know the correct format strings to use there is the option of making 2 calls to MagicParser_parse - the first call to extract category and then the second call to loop through all products.

The representation of the sub-arrays is a problem for the "simple" way in which Magic Parser tries to isolate the complexities of XML into a single dimensional array on a "per record" basis.

However, I am considering ways to deal with this. The reason why you only get the last option is because the derived key value is the same for each attribute, and is therefore overwritten during the parse; hense you only get the last one. What I need to do is check for an existing key of the same name and derive some modifier to indicate subsequent keys of that name.

Apologies that this is not an immediate solution; but i'm aware of this limitation and will be looking to support sub-array's as soon as possible.