XML Tutorials - Herong's Tutorial Notes
Dr. Herong Yang, Version 4.00

XML File Syntax Rules

This section describes 6 syntax rules of an XML file. A valid and simple XML file is also provided.

Syntax rules of an XML file:

  • Two XML elements can be nested by including one element as part of the content of the other element.
  • There must be only one element, called root element, that is not nested inside any other elements.
  • There must be one "xml" processing instruction before the root element.
  • Values of element attributes must be enclosed within two double quotes.
  • Element's tag and attribute's name must be made of alphanumeric characters and 4 additional characters: "-", "_", ":", and ".".
  • "instructions" in a processing instruction must be written in the same syntax as the attributes of an element.

That's it. As I said earlier, XML syntax is very simple.

A valid XML file:

<?xml version="1.0"?>
<dictionary>
<!-- valid.xml
   Copyright (c) 2002 by Dr. Herong Yang. http://www.herongyang.com/
-->
 <note>A valid & simple XML</note>
 <word>
  <name is_acronym="true" language="EN">POP</name>
  <definition>Post Office Protocol</definition>
  <definition>Point Of Purchase</definition>
 </word>
 <word>
  <update date="2002-12-23"/> 
  <name is_acronym="yes">XML</name>
  <definition>eXtensible Markup Language</definition>
  <note>Example: 
   <![CDATA[<?xml version="1.0"?><p>Hello world!</p>]]>
  </note>
 </word>
 <word>
  <update editor="Herong Yang"/> 
  <name>Markup</name>
  <definition>The amount added to the cost price to calculate 
the selling price - <i>Webster</i></definition>
 </word>
</dictionary>

Sections in This Chapter

Types of Information in XML Files

XML File Syntax Rules

The <?xml ...?> Processing Instruction

dictionary.xml - A Simple XML Sample File

Dr. Herong Yang, updated in 2009
XML File Syntax Rules