XML Introduction

  • Revision slug: XML_Introduction
  • Revision title: XML Introduction
  • Revision id: 120685
  • Created:
  • Creator: Taken
  • Is current revision? No
  • Comment 17 words added, 15 words removed

Revision Content

Summary: This article introduces the 'eXtensible Markup Language' (XML) and tells of it's uses.

What is XML?

XML is a markup language similar to HTML. It stands for Extensible Markup Language and is a W3C recommended specification as a general purpose markup language. This means, unlike other markup languages, XML is not predefined so you must define your own tags. The primary purpose of the language is the sharing of data across different systems, such as the Internet.

There are many languages based on XML; Some examples are XHTML, MathML, SVG, XUL, XBL, RSS, and RDF. You can also create your own.

"Correct" XML (Valid and Well-formed)

For an XML document to be correct it must be a well-formed document, conforming to all of XML's syntax rules, and valid, conforming to a specific language's rules.

Most browsers, including Mozilla, offer a debugger that can identify poorly-formed XML documents.

An example of a document that is not well formed is one with an element that has an opening tag with no closing tag and is not self-closing. In the below example this is exactly what is wrong.

Example

<message>
 <warning>
   Hello World
</message>

A correct example is shown below and is considered well formed.

<message>
 <warning>
   Hello World
 </warning>
</message>

To be valid, a XML document needs to conform to some semantic rules which are usually set in a XML Schema or an Document Type Definition. An example of a document that is not valid is a document that contains an undefined tag. For example if we never defined the warning tag then our document would not be valid.

Entities

Like HTML, XML offers methods (called entities) for referring to some special reserved characters (such as a greater than sign which is used for tags). There are five of these characters that you should know:

&lt; 	< 	      A less than sign.
&gt; 	> 	      A greater than sign.
&amp; 	& 	      Ampersand (And Sign).
&quot; 	" 	      A single quotation mark.
&apos; 	' 	      A single apostrophe.

Even though there are only 5 declared entities, more can be added using the document's Document Type Definition.

 <?xml version="1.0" encoding="UTF-8"?>
 <!DOCTYPE body [
     <!ENTITY warning "Warning: Something bad happened... please refresh and try again.">
 ]>
 <body>
   <message> &warning; </message>
 </body>

 

You can also use numeric character references to use special characters such as &#xA9; for a © sign. More information on this can be found in the Numeric character reference.

XML display

XML is usually used for description but there are ways to display XML data. Without defining a way for XML to display itself, raw XML code is shown in the browser.

One way to have a style on an XML page is to use CSS with the xml-stylesheet processing instruction.

<?xml-stylesheet type="text/css" href="stylesheet.css"?>

There is also another more powerful way to display XML, this is using the Extensible Stylesheet Language Transformations (XSLT) which can be used to transform XML into other languages such as HTML. This makes XML incredibly versatile.

<?xml-stylesheet type="text/xsl" href="transform.xsl"?>

Recommendations

This article is only a quick introduction to what XML is, with a few small examples and references to get you started and interested in XML. For more details about XML, you should look around on the Web for more in-depth articles.

Learning the HyperText Markup Language (HTML) will help you better understand XML. You should also explore the Mozilla Developer Center for more information.

A list of references on the web have been provided below:

The Using XML article is a great resource on information for transforming and creating your own language.

Document Information

{{ languages( { "es": "es/Introducci\u00f3n_a_XML", "fr": "fr/Introduction_\u00e0_XML", "ja": "ja/XML_Introduction", "pl": "pl/Wprowadzenie_do_XML-a", "zh-cn": "cn/XML_\u4ecb\u7ecd" } ) }}

Revision Source

<p><span class="comment">Summary: This article introduces the 'eXtensible Markup Language' (XML) and tells of it's uses.</span></p>
<h3 name="What_is_XML.3F">What is XML?</h3>
<p>XML is a markup language similar to HTML. It stands for Extensible Markup Language and is a <a class="external" href="http://www.w3.org/">W3C recommended</a> specification as a general purpose markup language. This means, unlike other markup languages, XML is not predefined so you must define your own tags. The primary purpose of the language is the sharing of data across different systems, such as the Internet.</p>
<p>There are many languages based on XML; Some examples are <a href="/en/XHTML" title="en/XHTML">XHTML</a>, <a href="/en/MathML" title="en/MathML">MathML</a>, <a href="/en/SVG" title="en/SVG">SVG</a>, <a href="/en/XUL" title="en/XUL">XUL</a>, <a href="/en/XBL" title="en/XBL">XBL</a>, <a href="/en/RSS" title="en/RSS">RSS</a>, and <a href="/en/RDF" title="en/RDF">RDF</a>. You can also create your own.</p>
<h3 name=".22Correct.22_XML_.28Valid_and_Well-formed.29">"Correct" XML (Valid and Well-formed)</h3>
<p>For an XML document to be correct it must be a well-formed document, conforming to all of XML's syntax rules, and valid, conforming to a specific language's rules.</p>
<p>Most browsers, including Mozilla, offer a debugger that can identify poorly-formed XML documents.</p>
<p>An example of a document that is not well formed is one with an element that has an opening tag with no closing tag and is not self-closing. In the below example this is exactly what is wrong.</p>
<p><strong>Example</strong></p>
<pre class="eval">&lt;message&gt;
 &lt;warning&gt;
   Hello World
&lt;/message&gt;
</pre>
<p>A correct example is shown below and is considered well formed.</p>
<p><code> </code></p>
<pre class="eval">&lt;message&gt;
 &lt;warning&gt;
   Hello World
 &lt;/warning&gt;
&lt;/message&gt;
</pre>
<p>To be valid, a XML document needs to conform to some semantic rules which are usually set in a XML Schema or an <a href="/en/DTD" title="en/DTD">Document Type Definition</a>. An example of a document that is not valid is a document that contains an undefined tag. For example if we never defined the warning tag then our document would not be valid.</p>
<h3 name="Entities">Entities</h3>
<p>Like HTML, XML offers methods (called entities) for referring to some special reserved characters (such as a greater than sign which is used for tags). There are five of these characters that you should know:</p>
<pre>&amp;lt; 	&lt; 	      A less than sign.
&amp;gt; 	&gt; 	      A greater than sign.
&amp;amp; 	&amp; 	      Ampersand (And Sign).
&amp;quot; 	" 	      A single quotation mark.
&amp;apos; 	' 	      A single apostrophe.
</pre>
<p>Even though there are only 5 declared entities, more can be added using the document's <a href="/en/DTD" title="en/DTD">Document Type Definition</a>.</p>
<pre> &lt;?xml version="1.0" encoding="UTF-8"?&gt;
 &lt;!DOCTYPE body [
     &lt;!ENTITY warning "Warning: Something bad happened... please refresh and try again."&gt;
 ]&gt;
 &lt;body&gt;
   &lt;message&gt; &amp;warning; &lt;/message&gt;
 &lt;/body&gt;
</pre>
<p> </p>
<p>You can also use numeric character references to use special characters such as &amp;#xA9; for a © sign. <span class="comment">More information on this can be found in the <a class="external" href="http://www.cookwood.com/entities/">Numeric character reference</a>.</span></p>
<h3 name="XML_display">XML display</h3>
<p>XML is usually used for description but there are ways to display XML data. Without defining a way for XML to display itself, raw XML code is shown in the browser.</p>
<p>One way to have a style on an XML page is to use <a href="/en/CSS" title="en/CSS">CSS</a> with the <code>xml-stylesheet</code> processing instruction.</p>
<pre>&lt;?xml-stylesheet type="text/css" href="stylesheet.css"?&gt;</pre>
<p>There is also another more powerful way to display XML, this is using the Extensible Stylesheet Language Transformations (<a href="/en/XSLT" title="en/XSLT">XSLT</a>) which can be used to transform XML into other languages such as HTML. This makes XML incredibly versatile.</p>
<pre>&lt;?xml-stylesheet type="text/xsl" href="transform.xsl"?&gt;</pre>
<h3 name="Recommendations">Recommendations</h3>
<p>This article is only a quick introduction to what XML is, with a few small examples and references to get you started and interested in XML. For more details about XML, you should look around on the Web for more in-depth articles.</p>
<p>Learning the HyperText Markup Language (<a href="/en/HTML" title="en/HTML">HTML</a>) will help you better understand XML. You should also explore the Mozilla Developer Center for more information.</p>
<p>A list of references on the web have been provided below:</p>
<ul> <li><a class="external" href="http://www.w3schools.com/xml/">W3Schools: XML Tutorial</a></li> <li><a class="external" href="http://www.w3schools.com/dtd/">W3Schools: DTD Tutorial</a></li> <li><a class="external" href="http://www.xml.com/">XML.com</a></li> <li><a class="external" href="http://www.w3.org/XML/">Extensible Markup Language (XML) @ W3.org</a></li> <li><a class="external" href="http://www.alistapart.com/d/usingxml/xml_uses_a.html">XML Example @ A List Apart</a></li> <li><a class="external" href="http://www.alistapart.com/articles/usingxml/">Using XML @ A List Apart</a></li>
</ul>
<p>The Using XML article is a great resource on information for transforming and creating your own language.</p>
<div class="originaldocinfo">
<h3 name="Document_Information">Document Information</h3>
<ul> <li>Author(s): <a class="external" href="http://justinshreve.com">Justin G. Shreve</a></li> <li>Last Updated Date: August 4th 2007</li>
</ul>
</div>
<p>{{ languages( { "es": "es/Introducci\u00f3n_a_XML", "fr": "fr/Introduction_\u00e0_XML", "ja": "ja/XML_Introduction", "pl": "pl/Wprowadzenie_do_XML-a", "zh-cn": "cn/XML_\u4ecb\u7ecd" } ) }}</p>
Revert to this revision