Dismiss Notice
Join Physics Forums Today!
The friendliest, high quality science and math community on the planet! Everyone who loves science is here!

Understanding XML

  1. Mar 18, 2007 #1

    DaveC426913

    User Avatar
    Gold Member

    What's the design difference between elements and attributes? What I'm asking is: what makes you decide that something should be an element versus an attribute?

    Code (Text):
    <pet>
      <name>Spike</name>
    </pet>
    i.e: which is better?
    Code (Text):
    <pet name="Spike">
    </pet>
    Does the difference lie in the fact that 'Spike' is likely to be user-facing content - as opposed to some behind-the-scenes value such as a width of 200?
     
    Last edited: Mar 18, 2007
  2. jcsd
  3. Mar 18, 2007 #2
  4. Mar 18, 2007 #3

    DaveC426913

    User Avatar
    Gold Member

    Thank you. The fact that this is a common question is good to know. And I do seem to be right on the money:

    You can use either, it's a matter of design and practicality which you decide to use. But in general, the rule of thumb seems to be:
    "...data goes in elements, metadata in attributes..."
     
    Last edited: Mar 18, 2007
  5. Mar 18, 2007 #4

    -Job-

    User Avatar
    Science Advisor

    Generally, i prefer attributes, unless the data is large or when the data may contain some special characters, such as <, >, in which case i opt for text nodes with <![CDATA[...]]>.
     
Know someone interested in this topic? Share this thread via Reddit, Google+, Twitter, or Facebook

Have something to add?



Similar Discussions: Understanding XML
  1. XQuery XML help (Replies: 1)

  2. Understanding Parsers (Replies: 3)

Loading...