Referencing a value from a list

Discussion in 'XML' started by Caroline M, Jan 29, 2007.

  1. Caroline M

    Caroline M Guest

    Hi there,

    I'm sure this has been posted before but I didn't know how to search
    for it because I don't know the name for what I am trying to do so
    I'll try and explain it as best I can.

    I have an application that captures some data about football players.
    I have fields for name, date of birth, nationality etc and things like
    position such as Goalkeeper, Striker etc. I need to store all this
    data in an XML file. In the case of the positions, I will populate a
    control in the program with a predetermined list of available
    positions (which also needs to be in the XML file) and then I simply
    select one from the list for each player. My question is, how do I
    store that for each player?

    If I have something like:

    <positions>
    <position>Goalkeeper</position>
    <position>Striker</position>
    ...
    </positions>
    <players>
    <player>
    <player_name>David Beckham</player_name>
    <player_position> ??? what goes here??? </player_position>
    ...
    </player>
    </players>

    What do I put in my player_position element above? Obviously one
    solution is simply to copy the text from the position element but
    thats not ideal because when I load the application from the XML file
    later I'd want to be able to populate the UI control with the
    available positions (which I might change the names of) and then
    indicate that David Beckham is in the first position in the list for
    exmple and avoid that duplication.

    I hope that makes sense!

    Thanks,
    Caroline Middlebrook
     
    Caroline M, Jan 29, 2007
    #1
    1. Advertising

  2. Caroline M

    Guest

    On Jan 29, 12:16 pm, "Caroline M"
    <> wrote:
    > I have an application that captures some data about
    > football players. I have fields for name, date of birth,
    > nationality etc and things like position such as
    > Goalkeeper, Striker etc. I need to store all this data in
    > an XML file.
    >
    > <positions>
    > <position>Goalkeeper</position>
    > <position>Striker</position>
    > ...
    > </positions>
    > <players>
    > <player>
    > <player_name>David Beckham</player_name>
    > <player_position> ??? what goes here???
    > </player_position>
    > ...
    > </player>
    > </players>
    >
    > What do I put in my player_position element above?
    > Obviously one solution is simply to copy the text from
    > the position element but thats not ideal because when I
    > load the application from the XML file later I'd want to
    > be able to populate the UI control with the available
    > positions (which I might change the names of) and then
    > indicate that David Beckham is in the first position in
    > the list for exmple and avoid that duplication.


    The following approach is oft used, especially by people
    with RDBMSy backgrounds:

    <football-data>
    <positions>
    <position id="1">Goalkeeper</position>
    <position id="2">Striker</position>
    </positions>
    <players>
    <player>
    <player_name position="1">David Beckham</player_name>
    </player>
    </players>
    </football-data>

    In this case, however, the following might be a bit better:

    <football-data>
    <positions>
    <position>
    <name>Goalkeeper</name>
    <players>
    <player>
    <name>David Beckham</name>
    </player>
    </players>
    </position>
    <position>
    <name>Striker</name>
    </position>
    </positions>
    </football-data>

    Also note that, depending on what you're using to process
    this data, you might want to simply do away with the
    positions element, store the positions' names within the
    player elements and populate whatever needs to be populated
    by selecting all the distinct values of player_position
    elements in the document. For that matter, depending on
    what your final goals (no pun intended) are, you might want
    to employ all three of the proposed representations--
    probably even more--and transform your data on the fly
    using XSLT. You would still need to choose one canonical
    representation of data, but it's hard to tell which one
    would be best without knowing much more about your project,
    so this decision is entirely up to you.

    --
    Pavel Lepin
     
    , Jan 29, 2007
    #2
    1. Advertising

  3. Caroline M

    George Bina Guest

    Hi Caroline,

    You can define an attribute, let's say for instance xml:id, for the
    position element and specify a unique value for each position. Then,
    in player_position you can have another attribute, for instance
    positionId and specify one of those values that you defined for
    position.
    Depending on the schema language that you use there are different ways
    to enforce this. Look for ID and IDREF.

    Best Regards,
    George
    ---------------------------------------------------------------------
    George Cristian Bina
    <oXygen/> XML Editor, Schema Editor and XSLT Editor/Debugger
    http://www.oxygenxml.com

    On Jan 29, 12:16 pm, "Caroline M"
    <> wrote:
    > Hi there,
    >
    > I'm sure this has been posted before but I didn't know how to search
    > for it because I don't know the name for what I am trying to do so
    > I'll try and explain it as best I can.
    >
    > I have an application that captures some data about football players.
    > I have fields for name, date of birth, nationality etc and things like
    > position such as Goalkeeper, Striker etc. I need to store all this
    > data in an XML file. In the case of the positions, I will populate a
    > control in the program with a predetermined list of available
    > positions (which also needs to be in the XML file) and then I simply
    > select one from the list for each player. My question is, how do I
    > store that for each player?
    >
    > If I have something like:
    >
    > <positions>
    > <position>Goalkeeper</position>
    > <position>Striker</position>
    > ...
    > </positions>
    > <players>
    > <player>
    > <player_name>David Beckham</player_name>
    > <player_position> ??? what goes here??? </player_position>
    > ...
    > </player>
    > </players>
    >
    > What do I put in my player_position element above? Obviously one
    > solution is simply to copy the text from the position element but
    > thats not ideal because when I load the application from the XML file
    > later I'd want to be able to populate the UI control with the
    > available positions (which I might change the names of) and then
    > indicate that David Beckham is in the first position in the list for
    > exmple and avoid that duplication.
    >
    > I hope that makes sense!
    >
    > Thanks,
    > Caroline Middlebrook
     
    George Bina, Jan 29, 2007
    #3
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Allan Horwitz

    Referencing listbox value error

    Allan Horwitz, Nov 25, 2003, in forum: ASP .Net
    Replies:
    2
    Views:
    418
    Allan Horwitz
    Dec 1, 2003
  2. darrel
    Replies:
    4
    Views:
    486
    darrel
    Jul 7, 2004
  3. =?Utf-8?B?TWlrZQ==?=

    Referencing value of a dynamically created control

    =?Utf-8?B?TWlrZQ==?=, Jul 13, 2004, in forum: ASP .Net
    Replies:
    1
    Views:
    401
    Davide Vernole [MVP]
    Jul 13, 2004
  4. Joshua Maurice
    Replies:
    0
    Views:
    309
    Joshua Maurice
    Nov 2, 2009
  5. gane
    Replies:
    0
    Views:
    159
Loading...

Share This Page