XML Tutorials

  Home arrow XML Tutorials arrow Page 2 - Creating a Well-Formed XML Document
XML TUTORIALS

Creating a Well-Formed XML Document
By: James Payne
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: 4 stars4 stars4 stars4 stars4 stars / 5
    2009-02-18

    Table of Contents:
  • Creating a Well-Formed XML Document
  • Mark Up
  • Getting a Root Element
  • Well-Formed

  •  
     

    SEARCH CODEWALKERS

    TOOLS YOU CAN USE

    advertisement

    Creating a Well-Formed XML Document - Mark Up


    (Page 2 of 4 )

     

    We used some content analysis in our previous article to uncover how to create XML elements and taxonomies. As a refresher, XML elements are made up of other elements and text or content. You can use attributes to further define and give more information about your elements or the content that they contain. In this example, we will create a new element called <album> and give it an attribute called <genre> to provide a better idea of what the content is all about: 

    <album genre="Rock and Roll"/> 

    This tells us that the album's genre is rock and roll. It is equivalent to using this code:  

    <album>

    <genre> Rock and Roll </genre>

    </album> 

    Which method you should use is largely a matter of opinion, but here are some guidelines for you to ask yourself: 

    1. Is part of your goal to give definition to a certain part of your element? An example would be the need to give information about a physical aspect of something, such as height, weight, width and so forth.

    2. Would you like to give more information about unique instances of an element? For instance, if you sold iPods, and some were white and others were red.

    3. Do you want to include more information with an element when it is being used?  

    If you answer yes to these questions, then you may wish to use the attribute method. As an example, perhaps you are doing a report on all of the albums sold. If you use <genre> as an attribute of <album>, the genre information will always be available on your report, as opposed to having to specify that yes, you would like to retrieve the genre as well. 

    More XML Tutorials Articles
    More By James Payne

    blog comments powered by Disqus

    XML TUTORIALS ARTICLES

    - Validation with Document Type Definitions (D...
    - Creating a Well-Formed XML Document
    - Getting to Know XML
    - A Friendly Approach to XML
    - Creating RSS 2.0 Feeds
    - Using Modules in Your RSS Feed
    - RSS 2.0
    - Querying XML: Use Cases
    - Joins and Query Use with XML
    - Solving Problems by Querying XML
    - Performing Set Operations When Querying XML
    - Querying XML
    - Handling Data for Ajax with JSON
    - Handling XML Data for Ajax
    - XML and JSON for Ajax


    © 2003-2012 by Developer Shed. All rights reserved. DS Cluster 1 - Follow our Sitemap