CodingForums.com

CodingForums.com (http://www.codingforums.com/index.php)
-   XML (http://www.codingforums.com/forumdisplay.php?f=3)
-   -   XML data structure (http://www.codingforums.com/showthread.php?t=285321)

tronman 01-05-2013 02:44 PM

XML data structure
 
Hi,

I'm a newbie to XML, with a problem. I want to create an XML file of events. Each event has a name, date and a number of links associated with it.

So it would be :
Name: Dogs v Cats
Date: 12/12/2013
Link: http://www.link1.com
Link: http://www.link2.com
Link: http://www.link3.com


Name: Birds v Ferrets
Date: 11/12/2013
Link: http://www.link4.com
Link: http://www.link5.com
Link: http://www.link6.com

Any idea on the best way to structure my XML file?

Thanks in advance!

tracknut 01-05-2013 03:26 PM

Is there a specific order to the list of links, and do you need to be able to look up (search for) specific links? Or are they just a set of links that will all get used together?

Do you have a starting xml that you've attempted?

Dave

tronman 01-05-2013 03:39 PM

Hi

I haven't attempted anything so far.

Actually I'm also looking to categorise links into groups (Blue links, red links, etc)

But they don't need listing in a specific order. I will be needing to look up the XML file and spit out events.

Any ideas?

tracknut 01-05-2013 04:18 PM

Why don't you give it a shot, this is a very simple XML example, a great starting point. But not even trying makes it seem like you're just looking for someone to write the code for you. Here's the W3Schools link to a bunch of XML examples to start with. Post your first try at it, and I'll be happy to help correct bugs etc.

Dave

denhamd2 01-08-2013 11:27 AM

Ok I've given it a go below. Please let me know if I'm on the right track?

Code:

<sport>

<animals>

<event>Dogs v Cats</event>
<date>12/12/2013</date>
<linkset>
<linktype>bluelinks</linktype>
<links>
<link>http://www.link1.com</link>
<link>http://www.link2.com</link>
<link>http://www.link3.com</link>
</links>
</linkset>


<event>Birds v Ferrets</event>
<date>11/12/2013</date>
<linkset>
<linktype>redlinks</linktype>
<links>
<link>http://www.link4.com</link>
<link>http://www.link5.com</link>
<link>http://www.link6.com</link>
</links>
</linkset>


</animals>

</sport>

What do you think?

sunfighter 01-08-2013 07:34 PM

The xml file is structured correctly. One way to check it is use a browser to look at it. Another way is to use an editor. Google XML NOTEPAD for a good one.

tracknut 01-08-2013 10:15 PM

It's a start, but your groupings are pretty odd, I think. Some questions:
1. You have a grouping of <animals> within <sport> - this would imply you are going to also have other non-animals sports, correct? If not, why would you have that additional layer of animals?
2. You do not have a grouping of each event, which seems odd to me. I would have listed a bunch of <event> groups (you have two in this example), to collect all the information together for each event.
3. You define an item called <linktype>, where I would use an attribute on the <link> tag, like this: <link type="red>http://www.link1.com</link>
4. You group the links together within <links>, and possibly you have a reason for this, but from what I can see so far, I'd say that's extraneous - just list each of the links.

Dave

tronman 01-15-2013 02:52 PM

Hi,

Thanks very much for the questions and tips. In answer to 1), yes there will be non-animal sports too, hence the need for this layer.

I've also implemented your suggestions. Please can you have a look below and let me know if this looks correct?

The big fix seemed to be grouping each event within its own tag. I added an ID to each as a unique identifier - is this the best way?

Code:

<sport>

<animals>

<event id="1">
<name>Dogs v Cats</name>
<date>12/12/2013</date>
<links>
<link type="red">http://www.link1.com</link>
<link type="blue">http://www.link2.com</link>
<link type="red">http://www.link3.com</link>
</links>
</event>

<event id="1">
<name>Birds v Ferrets</name>
<date>11/12/2013</date>
<links>
<link type="red">http://www.link4.com</link>
<link type="red">http://www.link5.com</link>
<link type="blue">http://www.link6.com</link>
</links>
</event>


</animals>

</sport>


denhamd2 01-15-2013 02:57 PM

Thanks very much for your help so far. In answer to your question 1 , no there will not be other non-animal sports, hence I removed this layer.

Please see below for my cleaned up version. For the event groupings I introduced, I gave each a unique ID - is this correct?

Code:

<sport>

<event id="1">
<name>Dogs v Cats</name>
<date>12/12/2013</date>
<links>
<link type="blue">http://www.link1.com</link>
<link type="red">http://www.link2.com</link>
<link type="red">http://www.link3.com</link>
</links>
</event>

<event id="2">
<name>Birds v Ferrets</name>
<date>11/12/2013</date>
<links>
<link type="red">http://www.link4.com</link>
<link type="red">http://www.link5.com</link>
<link type="blue">http://www.link6.com</link>
</links>
</event>

</sport>


tracknut 01-15-2013 04:06 PM

If the events need an ID, then sure, put one in. But if you have no use for an ID, then you could certainly just call it an <event> for each one. For example, if your program will need to directly pull up an event by referencing its ID (seems like a common need), then you'd want an ID. But if your program is simply listing all events, then no ID is needed.

And again on the <links>, is there a reason you have:
Code:

<links>
<link type="red">http://www.link4.com</link>
<link type="red">http://www.link5.com</link>
<link type="blue">http://www.link6.com</link>
</links>

instead of:
Code:

<link type="red">http://www.link4.com</link>
<link type="red">http://www.link5.com</link>
<link type="blue">http://www.link6.com</link>

A lot of this (general schema definition) depends on how you're going to use the data, how the functions will be written. That's why I'm asking these questions... it's not that your schema is wrong, just that if I were writing the code to access it, I wouldn't use some of the items you've included.

Dave

denhamd2 01-25-2013 10:44 AM

Hi,

Thanks again for the reply.

You're right I guess it does depend how I'm going to use the data.

So what I want to do is to be able to list all links for the "Dogs vs Cats" event.

But I also want to be able to add more links to the "Dogs vs Cats" event over time. How this will happen is I'll pull data from other websites, and if the event name matches "Dogs vs Cats", then add the links to that event. So do you think in this case, the <links> layer would be unnecessary?

ikuvae22 02-17-2013 01:27 PM

I know about xml. But can not help you. Because, I don't know details about it.


All times are GMT +1. The time now is 08:31 AM.

Powered by vBulletin®
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.