Click here to Skip to main content
15,905,915 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have a question about making a category for the E-commerce website.

I have just known XML and do not understand that much.
I am intending to build simple mobile store, online with 4 categories: Nokia, Motorola, Samsung, LG.

But I don't know what should I do - create single XML file that contain all products of each category or 4 separate XML files for each category.?

E.g. of single XML file:
<?xml version="1.0" encoding="ISO-8859-1"?>
<mobilecata>
     <phone category="Nokia">
         <name>N95 mini</name>
         <price>$850</price>
     </phone>
     
     <phone category="LG">
         <name> LG500</name>
         <price>$300</price>
     </phone>
     .
     .
</mobilecata>

If you have experience of building E-commerce website, please help me in this question. I really appreciate your suggestions.

Thanks.
Posted
Updated 11-Aug-10 3:35am
v2

1 solution

It would be best to send only the information the user requests. If a user would like info on one brand only it would be a waste to send all the information about all the different brands.

Personally I also wouldn't recommend using the brand name as category because this isn't completely right and makes it harder to process easy later. Category would be better defined for example as product type (at storage level, like in the database), but since you don't have other products besides phones this isn't relevant now.

A category is just a group definition like, all phones with a price below $200 or could also simply be the brand name. The only difference is that it wouldn't be that practical to structure the data that way. Because you would also need a definition where you have xml elements for each price range.

How about this?

XML
<?xml version="1.0" encoding="ISO-8859-1"?>
<productlist>
   <phone>
      <brand>Nokia</brand>
      <name>N95 mini</name>
      <price>850</price>
   </phone>
   <phone>
      <brand>LG</brand>
      <name>LG500</name>
      <price>400</price>
   </phone>
</productlist>


It would now be way easier to select categories in any way you want based on the product information.

Some simple xslt examples:
XML
<pre>
<xsl:template match="/">
   <xsl:for-each select="productlist/phone[price&gt;400]">
      <!-- all phones with a price below $400 -->
      <xsl:value-of select="brand"/>
      <xsl:value-of select="name"/>
      <xsl:value-of select="price"/>
   </xsl:for-each>
   <xsl:for-each select="productlist/phone[brand='nokia']">
      <!-- all nokia phones -->
      <xsl:value-of select="brand"/>
      <xsl:value-of select="name"/>
      <xsl:value-of select="price"/>
   </xsl:for-each>
</xsl:template>
</pre>


More info on xslt and xpath:
http://www.w3schools.com/xsl/default.asp[^]
http://www.w3schools.com/XPath/default.asp[^]

Hopefully this answer gave you some nice ideas.

Good luck!
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900