Results 1 to 4 of 4

Thread: XML Document, HELP!

  1. #1

    Thread Starter
    Fanatic Member
    Join Date
    Oct 2001
    Location
    Three Anchor Bay, Cape Town, South Africa
    Posts
    769

    Unhappy XML Document, HELP!

    Hi,

    I am a little confused about when you should use what. Here's an example:

    Should I use this xml:
    Code:
    <person>
       <name>shunt</name>
    </person>
    or should I use this xml:

    Code:
    <person name="shunt"/>
    Can anyone tell me which one would be correct and why.

  2. #2
    Black Cat JoshT's Avatar
    Join Date
    Nov 2000
    Location
    WNY, USA
    Posts
    4,032
    It depends on your requirements - if the person could have more than one name, you would need to use #1, so it really depends on your data model.
    Josh
    Get these: Mozilla Opera OpenBSD
    I have books for sale: "MCSD in a Nutshell" and "VB Distributed Exam Cram" - PM me for details. Will also trade for a decent ATX Pentium 2 MB/CPU/RAM combo.

  3. #3
    Fanatic Member twanvl's Avatar
    Join Date
    Dec 2001
    Posts
    771
    Attibutes are easier to use (shoter to write), and usually more clear.
    But when you are planning to 'divide' the value or add extra options somewhere in the future it's better to use a child element right away.

    Maybe sometime you want to be able to wite this:
    Code:
    <person>
        <name>
            John Johnes
        </name>
        <name>
            <first-name>Bill</first-name>
            <last-name>Gates</last-name>
        </name>
    </person>
    You should also consider how you are going to edit these XML files. If you are using a text editor attributes have the benefit of being more readable. If you use some kind of XML editor, there is hardly any reason not to use child elements.

  4. #4
    Lively Member
    Join Date
    Jul 2001
    Location
    USA
    Posts
    95
    Also by going with attributes makes the file smaller.

Posting Permissions

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



Click Here to Expand Forum to Full Width