Home arrow XML arrow Page 4 - Introduction to XML
XML

Introduction to XML


This is chapter one from the book, XML and FrameMaker, by Kay Ethier (Apress, ISBN: 159059276X. 2004). Ethier reviews some of the basic XML terms and rules, and provides a basic overview of the purpose of DTDs and XSLT.

Author Info:
By: Kay Ethier
Rating: 5 stars5 stars5 stars5 stars5 stars / 8
June 15, 2004
TABLE OF CONTENTS:
  1. · Introduction to XML
  2. · A Review of Basic Terminology
  3. · Terminology Continued
  4. · Understanding XML Rules (1-3)
  5. · Understanding XML Rules (4-5)
  6. · Understanding XML Rules (6-7)
  7. · Looking at XML with Formatting

print this article
SEARCH DEVARTICLES

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.


blog comments powered by Disqus
XML ARTICLES

- Open XML Finally Supported by MS Office
- XML Features Added to Two Systems
- Using Regions with XSL Formatting Objects
- Using XSL Formatting Objects
- More Schematron Features
- Schematron Patterns and Validation
- Using Schematron
- 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

Watch our Tech Videos 
Dev Articles Forums 
 RSS  Articles
 RSS  Forums
 RSS  All Feeds
Write For Us 
Weekly Newsletter
 
Developer Updates  
Free Website Content 
Contact Us 
Site Map 
Privacy Policy 
Support 

Developer Shed Affiliates

 




© 2003-2017 by Developer Shed. All rights reserved. DS Cluster - Follow our Sitemap
Popular Web Development Topics
All Web Development Tutorials