Web Analytics Made Easy -
StatCounter What's the correct use of XML? - CodingForum

Announcement

Collapse
No announcement yet.

What's the correct use of XML?

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • What's the correct use of XML?

    Hi,

    I'm planning on using an XML-file as input for a php-script. While designing the XML-file I came across 2 different ways to store the data. Method 1 using just xml-tags and method 2 using attributes inside the tags.

    Method 1:

    PHP Code:
    <cookbook>
     <
    recipe>
      <
    id>
       
    1
      
    </id>
      <
    name>
       
    Spaghetti Carbonara
      
    <name>
      <
    ingredients>
       
    etc.
       
    etc.
      </
    ingredients>
     </
    recipe>
    </
    cookbook
    Method 2:

    PHP Code:
    <cookbook>
     <
    recipe id="1" name="Spaghetti Carbonara">
      <
    ingredients>
       
    etc.
       
    etc.
      </
    ingredients>
     </
    recipe>
    </
    cookbook
    What is the correct (or recommended) way to use XML for data storage?

    Thanx! Michiel

  • #2
    Personal preference. Either one works.

    That's the beauty of XML. It doesn't dictate a specific format for your document. A <!DOCTYPE > declaration tag specifies the Document Type Definition (DTD) used to do that.

    It really depends on what's easiest for you.
    "The first step to confirming there is a bug in someone else's work is confirming there are no bugs in your own."
    June 30, 2001
    author, ES-Membrane project (Github Pages site)
    author, Verbosio prototype XML Editor
    author, JavaScript Developer's Dictionary
    https://alexvincent.us/blog

    Comment


    • #3
      The great thing about XML is that it's all about semantics & metadata, but this can often be a problem too...

      As a general rule of thumb, if something is only going to exist once within a given element, it should be an attribute instead of a separate child element, but there's no hard & fast rules - it's completely up to you.

      Marcus Tucker / www / blog
      Web Analyst Programmer / Voted SPF "ASP Guru"

      Comment

      Working...
      X