XML.HTMLTeacher.Com
[Search] [Contact] [Sitemap]
XML
[Main]
[XML]
[Creation Guidelines]
[Classes]
[XHTML]
[XML]
[CSS]
[Design]
[Programming]
[Marketing]

* XML documents are saved with the extension, .xml

Naming Conventions
  • Names are case sensitive. FirstName is different from firstname and fiRStnaMe.
  • Names may begin with a letter, underscore or colon.
  • Names may contain digits, underscores, hyphens, periods and colons.
    (Colons, however, are generally reserved for Namespaces and should be avoided.)
  • Names cannot begin with the letters, xml in any case. These letters are reserved by the XML specification.
  • Names may not contain spaces.
XML Declaration
* All .xml documents must contain the following XML declaration at the beginning of the document.

<?xml version="1.0"?>

* This XML declaration MUST be stated as the first line of the document. There cannot be a line break before this declaration.

* If a DTD is utilized, then the <!DOCTYPE> element must be declared. The DTD may either be embedded within the XML document or linked to the XML document.

A linked DTD Declaration:
<!DOCTYPE RootElement SYSTEM/PUBLIC "URL/filename.dtd">

An embedded DTD Declaration:
<!DOCTYPE RootElement
[
DTD Elements
]>


* If a schema is utilized, the schema components are added to the root element of the XML document.

A schema declaration without a namespace:
<Plants xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="URL/filename.xsd">


A schema declaration that includes a namespace:
<library:Plants

xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"

xmlns:library="http://www.xml.htmlteacher.com/library"

xsi:schemaLocation=
"http://www.xml.htmlteacher.com/library/library.xsd">


* When using either a DTD or a schema to validate an XML document, use the attribute and value of standalone="no" within the xml declaration.

<?xml version="1.0" standalone="no"?>

* The <? and <! are called Markup Declaration Open (MDO). They are processing instructions.


Root Element
* An XML document must contain one element that completely contains all the other elements. That element must be unique from any other elements stated within that document. For example, in HTML, the root element is <html> to signify the beginning of the document and the closing element is </html> that signifies the end of the HTML document.

Empty Elements
* Empty elements must contain an ending tag or a closing bracket within the start tag.

<img />

or

<img></img>


Nesting Elements
* Elements must be nested correctly. For example:

<p>content <i>content</i> content</p>

and NOT like this:

<p>content <i>content content</p></i>

Correct XML:

<employee>
<first_name>Sonia</first_name>
<last_name>Weimann</last_name>
</employee>


Incorrect XML:

<employee>
<first_name>Sonia<last_name>
</first_name>Weimann</last_name>
</employee>
</last_name>


Attributes and Values
* All attributes require values and all values must be surrounded by single or double quotes.

* Double or single quotes may be used within the value stated for the attribute. If the value contains single quote(s), enclose the value within double quotation marks. If the value contains double quote(s), enclose the value within single quotation marks.


Ending Tags
* Each tag stated within the XML document must be closed either with another tag or within itself. In HTML, it is acceptable to omit the closing tags of some elements as in <li> and <p> but not in XHTML or XML.

Correct:
<first_name>Sonia</first_name>

<product id="t1234" />

Incorrect:
<first_name>Sonia

<product id="t1234">


Character Entities
* Only 5 entities are allowed to be written in XML without requiring their being stated within a DTD. All other character entities must be specified within a DTD.

< (lesser than)
> (greater than)
& (ampersand)
" (double quote)
' (single quote)

* The symbols, < and &, are not allowed within the XML document except to begin a tag or entity, respectively. If these symbols are necessary within the document, the escape codes must be used.

& = &amp;
< = &lt;


Comments and CDATA
* Comments in XML are written exactly like HTML comments:

<!-- Comment -->

* This format is used when short instructions are to be written into the XML document and will not contain any elements such as <acronym>.

* Comments may not contain two hyphens in a row, other than at the beginning and at the end of the comment.

* Use CDATA for commenting out a greater amount of text and/or if elements are to be included. CDATA must be written in upper case. An example of CDATA:

<![CDATA

[Comment information]

]>


* Both comment tags and CDATA cannot be nested within one another. Neither are CDATA sections allowed to be nested within one another not are comment tags.

* CDATA sections must be added after the <?xml> declaration and only between elements. Comments, however, may be added immediately after the <?xml> declaration.


Follow the DTD or Schema
* If the XML document will follow a DTD or schema, read and understand this document as it will form the basis of the XML document. It will let you know what tags to use and what the attributes and their values will be. In other words, it will provide you with the structure tree to create a valid XML document.


All materials, tutorials and content are copyrighted by HTMLTeacher.Com.
Any use of any material, tutorials and/or content provided by this site is prohibited without expressed written consent of the author.

Copyright ©2003 HTMLTeacher.Com and Sonia Weimann