XML
  Home arrow XML arrow Page 4 - Introduction to XML
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  
Dedicated Servers  
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

Introduction to XML
By: Kay Ethier
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: 4 stars4 stars4 stars4 stars4 stars / 4
    2004-06-15

    Table of Contents:
  • Introduction to XML
  • A Review of Basic Terminology
  • Terminology Continued
  • Understanding XML Rules (1-3)
  • Understanding XML Rules (4-5)
  • Understanding XML Rules (6-7)
  • Looking at XML with Formatting

  • 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


    Introduction to XML - Understanding XML Rules (1-3)


    (Page 4 of 7 )

    What do you need to do to create an XML document? At the simplest level, you need a text editor in which you can type. On the other end of the spectrum, you may need an XML editing program; a validation tool; a DTD and DTD editor; XSL or CSS for formatting; and a repository for storage, tracking, and retrieval. 

    In this section, I cover simple rules that XML documents need to If you follow XML follow. Examples in this section serve to clarify the rules of XML, with each addressing a specific aspect of XML. The numbering on the rules (Rule 1, Rule 2, ...) is just to help you in your reading.

    Rule 1: If you have an XML declaration, it must be the first line of the document.

    While an XML declaration is not required, it can be helpful when bringing XML into different tools. The XML declaration is located at the top of your XML file and helps tools (and readers) identify the file as XML, rather than SGML or some other markup. An XML declaration may look like this:

    <?xml version="1.0"?>

    If you have many small XML documents-XML fragments-that you plan to store and assemble, you might want to omit the declaration.That way, you do not end up with multiple declarations in an assembled file. This scenario will cause an error, since the declaration cannot occur below any content.

    If you plan to produce valid XML, please note that you must have a declaration for an XML document to be valid.

    Rule 2: All XML documents must have a root element.

    In the example below, the root element is <zoo>. This root element begins the XML and its corresponding end tag </zoo> comes after all the content in the document, as shown in the following code:

     <?xml version="1.0"?>
    <zoo>
    Zoo Document Content
    </zoo>

    Rule 3: All XML elements must be properly nested within the root element.

    Items are nested inside the <zoo> root, as shown in the following code. These nested items include an <animals> child element. Inside this child element are additional elements called and . These are nested child elements.

    <?xml version="1.0"?>
    <zoo>
       <animals>
          <cat>Leo</cat>
          <reptile>Pudgie</reptile> 
      </animals>
    </zoo>

    NOTE: Spaces in front of the lines of code, as used in examples, are to help you see the beginning and end tags and the element nesting. This spacing is not required.

    The preceding code snippet shows proper nesting. The tags begin and end without intermingling with other tags. An improper version might look like the following code:

    <?xml version="1.0"?>
    <zoo>
      <animals>
        <cat>Leo 
        <reptile>Pudgie</cat></reptile>
      </animals>
    </zoo>

    What is incorrect is that the end tag is inside the reptile start and end tags. The nesting is incorrect because the tags cannot fold inside other tags unless they do so completely. Mathematically speaking, it is the equivalent of mixing up parentheses in a grouping, as illustrated in the following example:

    (x + y)/z

    does not have the same meaning as:

    (x + y/z)

    In these equations, having the parentheses in different locations changes what is divided by z and thereby change the value of the equation. In the first equation, x + y is divided by z, while in the second equation y alone is divided by z and then the result is added to x. So, placement of parentheses is important to getting the correct result. As with the equation above, to produce appropriate structure in XML it is necessary to properly nest the beginning and end tags.

    This chapter is from XML and Framemaker, by Kay Ethier (Apress, 2004, ISBN: 159059276X). Check it out at your favorite bookstore today.

    Buy this book now.

    More XML Articles
    More By Kay Ethier


     

    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 4 hosted by Hostway