XML
  Home arrow XML arrow Page 4 - XML Basics - Part One
Dev Articles Forums 
ADO.NET  
Apache  
ASP  
ASP.NET  
C#  
C++  
ColdFusion  
COM/COM+  
Delphi-Kylix  
Design Usability  
Development Cycles  
DHTML  
Embedded Tools  
Flash  
Graphic Design  
HTML  
IIS  
Interviews  
Java  
JavaScript  
MySQL  
Oracle  
Photoshop  
PHP  
Reviews  
Ruby-on-Rails  
SQL  
SQL Server  
Style Sheets  
VB.Net  
Visual Basic  
Web Authoring  
Web Services  
Web Standards  
XML  
Moblin 
JMSL Numerical Library 
IBM® developerWorks 
Sun Developer Network 
Weekly Newsletter
 
Developer Updates  
Free Website Content 
 RSS  Articles
 RSS  Forums
 RSS  All Feeds
Write For Us Get Paid 
Request Media Kit
Contact Us 
Site Map 
Privacy Policy 
Support 
 USERNAME
 
 PASSWORD
 
 
  >>> SIGN UP!  
  Lost Password? 
XML

XML Basics - Part One
By: Liviu Tudor
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: 5 stars5 stars5 stars5 stars5 stars / 83
    2003-12-15

    Table of Contents:
  • XML Basics - Part One
  • Brief History of Data Exchange
  • The Need for XML
  • DTD, Schema and Valid XML
  • DTD

  • Rate this Article: Poor Best 
      ADD THIS ARTICLE TO:
      Del.ici.ous Digg
      Blink Simpy
      Google Spurl
      Y! MyWeb Furl
    Email Me Similar Content When Posted
    Add Developer Shed Article Feed To Your Site
    Email Article To Friend
    Print Version Of Article
    PDF Version Of Article
     
     
    ADVERTISEMENT


    XML Basics - Part One - DTD, Schema and Valid XML


    (Page 4 of 5 )

    Remember earlier on when I mentioned the term “grammar” when talking about XML? Well, that’s what “grammar” is for.  As each human language has a set of rules defining how the atoms are grouped to form a phrase, XML allows us to define rules upon how an XML document should be created.

    “Why rules?” the sceptics ask.  “Isn’t XML meant to be a meta language where we define our own tags and make our own rules?”  True – XML allows you to define your own tags, your own “rules” and your own “language”, and it doesn’t enforce you to assign a “grammar” to it whatsoever – as stated before, both pieces of XML presented above are perfectly valid, and even more so, you can find all sorts of other variations to represent the same logical entity. However, when you want your XML document to be “read” and “understood” by a third party, this third party will need to know about your XML “language” in order to make sense of it. Going back to the example with human languages, for somebody who doesn’t speak English, the phrase “the quick brown fox jumps over the lazy dog” will be absolutely meaningless and as far as s/he is concerned, might not even be in English! Put an English dictionary and an English grammar book next to it (err, ok, and a few years of practice) and it is all perfectly understandable – even more, put a Windows logo next to it and the person will actually know you’re talking about the Fonts applet in the Control Panel!  Same thing happens with XML: feed some XML tags in an application, and if you do the magic dance around it at midnight, it might actually understand the logical contents of your document; however, describe the contents of this XML document and the dance more than likely will not be needed (could this be the reason why there are so few programmers going to the disco-clubs nowadays? :O)

    There are two ways to describe an XML “grammar”: through a DTD (Document Type Definition) and through an XML Schema. We’ll have a look briefly at each one of them shortly. Before that though, let’s look at one simple thing: take the previous example and wrap it all up into one single XML document like this:

    <?xml version="1.0" encoding="UTF-8"?>
    <Employee>
     <Name>Liviu</Name>
     <Surname>Tudor</Surname>
     <Birthday>14/02/1975</Birthday>
    </Employee>

    This represents a valid XML document.  If we have a look at this now:

    <?xml version="1.0" encoding="UTF-8"?>
    <Employee>
     <Name>Liviu
     <Surname>Tudor
     <Birthday>14/02/1975
    </Employee>

    It “nearly” looks the same as the previous one – however, this second form is not a valid XML document? Therefore, such XML will be rejected by any XML-enabled application as “invalid data” or such.

    It is then about time we introduce the term “valid XML”: this is a document that follows the XML convention:

    • it has one single root element
    • tags are not interlaced
    • And every opening tag has an ending tag pair.

    A document can “look” like an XML document, but not be a valid XML document – if you consider HTML (which is full of such tags that do not have an ending tag – for example <p>), even though that it is a meta language built on tags, it does not resemble a valid XML document (there is though nowadays something called XHTML which combines both XML and HTML.  From my experience, websites are now starting to transition over to XHTML). Even more, a document can have pairs of open/close tags, and still not be considered a valid XML document – for example:

    <?xml version="1.0" encoding="UTF-8"?>
    <Employee>
     <Name>Liviu</Name>
     <Surname>Tudor<Birthday>14/02/1975</Surname></Birthday>
    </Employee>

    Now, assuming we have a valid XML structure, how do we know that the actual data represented by the XML document is logically correct? For example, how do we know that this structure:

    <?xml version="1.0" encoding="UTF-8"?>
    <Employee>
     <Name>Liviu</Name>
     <Surname>Tudor</Surname>
     <Birthday>14/02/1975</Birthday>
    </Employee>

    is logically correct and the application that produced the XML didn’t intend to “say” instead something like this:

    <?xml version="1.0" encoding="UTF-8"?>
    <Employee Name=”Liviu” Surname=”Tudor”>
     <Date Birthday=”14/02/1975” />
    </Employee>

    Even more, as pointed out earlier as well, how do we know that the Birthday is a correct date? We can only tell this based on the XML “grammar” – be it a DTD or an XML Schema.

    More XML Articles
    More By Liviu Tudor


     

    XML ARTICLES

    - Datatypes and More in RELAX NG
    - Providing Options in RELAX NG
    - An Introduction to RELAX NG
    - Path, Predicates, and XQuery
    - Using Predicates with XQuery
    - Navigating Input Documents Using Paths
    - XML Basics
    - Introduction to XPath
    - Simple Web Syndication with RSS 2.0
    - Java UI Design with an IDE
    - UI Design with Java and XML Toolkits
    - Displaying ADO Retrieved Data with XML Islan...
    - Widget Walkthrough
    - Introduction to Widgets
    - The Why and How of XML Data Islands






    © 2003-2008 by Developer Shed. All rights reserved. DS Cluster 6 hosted by Hostway
    Stay green...Green IT