...

View Full Version : New to XML - Nesting?



Clan57
07-02-2009, 04:59 AM
Hi, I've just started reading about XML and I decided to make a simple beer database to get started. Once I got into it I wanted to add more and more detailed data to the file, but I'm concerned about my formatting, how the data will be displayed and if there's such a thing as too much nesting, I don't want to form any bad habits so I was wondering if the users here could provide some advice.

Here's where the issue starts, I have 1 beer, and that beer comes in different sizes (500ml cans, 330 ml bottles etc.), it also ships in different case sizes (single, six pack, twenty-four) so each size and case has a different price. What would be the best way to store this data? I thought about putting soem of the data in the tags itself such as the <ml650> tag shown below, but I have a feeling that's a bad idea?

TLDR Version: Is there a better way to store this data?



<beerDatabase>

<beer>

<name>Saporro</name>
<alcohol>5%</alcohol>
<country>Japan</country>

<ml650>
<price>
<individual>$2.00</individual>
<six>$12.00</six>
<twelve>$24.00</twelve>
<twentyfour>$48.00</twentyfour>
</price>
</ml650>

<ml330>
<price>
<individual>$1.00</individual>
<six>$8.00</six>
<twelve>$16.00</twelve>
<twentyfour>$32.00</twentyfour>
</price>
</ml330>

<goodness>good</goodness>

</beer>

</beerDatabase>

Alex Vincent
07-02-2009, 06:01 PM
XML is usually not the right way to store data. It's great for communicating data between a server and a client, but it's far too verbose for data storage in most cases. You probably want an actual database, like MySQL.

Clan57
07-12-2009, 05:29 AM
Thanks for the reply. Basically what I was hoping to do was setup the data in an XML document for transfer later on into an SQL or Access Database. My reasoning for this is that I don't have time to really read into SQL/MySQL and I remember reading learning about XML awhile ago and it seemed like a simple and fast way for me to throw in some data and transfer later on. This way I could get some experience using XML in general and also exporting it to different applications.

Well maybe that's not the best idea, but in either case just out of curiousity I wouldn't mind having your thoughts on the nesting issue too =)

Thanks!



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum