Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 11 of 11
  1. #1
    New to the CF scene
    Join Date
    Oct 2006
    Posts
    4
    Thanks
    0
    Thanked 0 Times in 0 Posts

    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!

  • #2
    Senior Coder
    Join Date
    Aug 2006
    Posts
    1,297
    Thanks
    10
    Thanked 282 Times in 281 Posts
    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

  • #3
    New to the CF scene
    Join Date
    Oct 2006
    Posts
    4
    Thanks
    0
    Thanked 0 Times in 0 Posts
    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?

  • #4
    Senior Coder
    Join Date
    Aug 2006
    Posts
    1,297
    Thanks
    10
    Thanked 282 Times in 281 Posts
    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

  • #5
    New Coder
    Join Date
    Sep 2004
    Posts
    96
    Thanks
    1
    Thanked 0 Times in 0 Posts
    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?

  • #6
    Senior Coder
    Join Date
    Jan 2011
    Location
    Missouri
    Posts
    4,300
    Thanks
    23
    Thanked 612 Times in 611 Posts
    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.

  • #7
    Senior Coder
    Join Date
    Aug 2006
    Posts
    1,297
    Thanks
    10
    Thanked 282 Times in 281 Posts
    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

  • #8
    New to the CF scene
    Join Date
    Oct 2006
    Posts
    4
    Thanks
    0
    Thanked 0 Times in 0 Posts
    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>

  • #9
    New Coder
    Join Date
    Sep 2004
    Posts
    96
    Thanks
    1
    Thanked 0 Times in 0 Posts
    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>

  • #10
    Senior Coder
    Join Date
    Aug 2006
    Posts
    1,297
    Thanks
    10
    Thanked 282 Times in 281 Posts
    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

  • #11
    New Coder
    Join Date
    Sep 2004
    Posts
    96
    Thanks
    1
    Thanked 0 Times in 0 Posts
    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?


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •