Go Back   CodingForums.com > :: Client side development > XML

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 01-05-2013, 02:44 PM   PM User | #1
tronman
New to the CF scene

 
Join Date: Oct 2006
Posts: 4
Thanks: 0
Thanked 0 Times in 0 Posts
tronman is an unknown quantity at this point
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!
tronman is offline   Reply With Quote
Old 01-05-2013, 03:26 PM   PM User | #2
tracknut
Regular Coder

 
Join Date: Aug 2006
Posts: 891
Thanks: 4
Thanked 205 Times in 204 Posts
tracknut is an unknown quantity at this point
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
tracknut is offline   Reply With Quote
Old 01-05-2013, 03:39 PM   PM User | #3
tronman
New to the CF scene

 
Join Date: Oct 2006
Posts: 4
Thanks: 0
Thanked 0 Times in 0 Posts
tronman is an unknown quantity at this point
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?
tronman is offline   Reply With Quote
Old 01-05-2013, 04:18 PM   PM User | #4
tracknut
Regular Coder

 
Join Date: Aug 2006
Posts: 891
Thanks: 4
Thanked 205 Times in 204 Posts
tracknut is an unknown quantity at this point
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
tracknut is offline   Reply With Quote
Old 01-08-2013, 11:27 AM   PM User | #5
denhamd2
New Coder

 
Join Date: Sep 2004
Posts: 79
Thanks: 0
Thanked 0 Times in 0 Posts
denhamd2 is an unknown quantity at this point
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?
denhamd2 is offline   Reply With Quote
Old 01-08-2013, 07:34 PM   PM User | #6
sunfighter
Senior Coder

 
Join Date: Jan 2011
Location: Missouri
Posts: 2,365
Thanks: 18
Thanked 348 Times in 347 Posts
sunfighter is on a distinguished road
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.
sunfighter is offline   Reply With Quote
Old 01-08-2013, 10:15 PM   PM User | #7
tracknut
Regular Coder

 
Join Date: Aug 2006
Posts: 891
Thanks: 4
Thanked 205 Times in 204 Posts
tracknut is an unknown quantity at this point
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
tracknut is offline   Reply With Quote
Old 01-15-2013, 02:52 PM   PM User | #8
tronman
New to the CF scene

 
Join Date: Oct 2006
Posts: 4
Thanks: 0
Thanked 0 Times in 0 Posts
tronman is an unknown quantity at this point
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>
tronman is offline   Reply With Quote
Old 01-15-2013, 02:57 PM   PM User | #9
denhamd2
New Coder

 
Join Date: Sep 2004
Posts: 79
Thanks: 0
Thanked 0 Times in 0 Posts
denhamd2 is an unknown quantity at this point
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>
denhamd2 is offline   Reply With Quote
Old 01-15-2013, 04:06 PM   PM User | #10
tracknut
Regular Coder

 
Join Date: Aug 2006
Posts: 891
Thanks: 4
Thanked 205 Times in 204 Posts
tracknut is an unknown quantity at this point
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
tracknut is offline   Reply With Quote
Old 01-25-2013, 10:44 AM   PM User | #11
denhamd2
New Coder

 
Join Date: Sep 2004
Posts: 79
Thanks: 0
Thanked 0 Times in 0 Posts
denhamd2 is an unknown quantity at this point
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?
denhamd2 is offline   Reply With Quote
Old 02-17-2013, 01:27 PM   PM User | #12
ikuvae22
New Coder

 
Join Date: Jan 2013
Location: Bangladesh
Posts: 15
Thanks: 0
Thanked 0 Times in 0 Posts
ikuvae22 is an unknown quantity at this point
I know about xml. But can not help you. Because, I don't know details about it.
ikuvae22 is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 12:03 AM.


Advertisement
Log in to turn off these ads.