Home : Tutorials : XML Tutorial


logo.gif (8216 bytes)
 

Tags


XML is very similar to HTML. It has tags, which identify elements. These tags also contain attributes about these elements. In XML a Tag is what is written between angled brackets, i.e. XML tags open with the < symbol and end with the > symbol. They always come in and  matched pairsm, with the defined element between the open and close tag.

<composer> is an example for an opening tag. In XML all opening Tags must have  closing tags, in this case the closing tag would look like this: </composer>. Most of you will already be familiar with tags from HTML and SGML.

Element

<composer>Mozart</composer>

Start Tag
The beginning of every non-empty XML element is marked by a start-tag.
An example of a start-tag: 

<composer>

End Tag
The end of every non-empty XML element is marked by a end-tag.
An example of an end-tag:

</composer>

Element Content
The text between the start-tag and end-tag is called the element's content. The element content in this case would be:

Mozart

Empty Element Tag
If an element is empty, it must be represented either by a start-tag immediately followed by an end-tag or by an empty-element tag. An empty-element tag takes a special form:

<BR/>...empty element tag in XML, or
<BR></BR>

As opposed to HTML where a line break is declared with:

<BR>...start tag without an end tag

Empty-element tags may be used for any element which has no content, whether or not it is declared using the keyword EMPTY (see chapter on Element Type Declaration). For interoperability, the empty-element tag must be used, and can only be used, for elements which are declared EMPTY. Examples of empty elements:

<IMG align="center" scr="logo.gif"/>
<BR></BR>

 

Element Type
The Name in the start- and end-tags gives the element's type. In our example it would be
composer.

The Name-AttValue pairs are referred to as the attribute specifications of the element, with the Name in each pair referred to as the attribute name and the content of the AttValue as the attribute value. In the following example we have an empty element 'IMG' and two attributes 'align' and 'src'.

<IMG align="center" src="logo.gif"/>

 

As you will see later on in the tutorial, XML and HTML markup will be used in the same document. By convention put HTML tags in upper case and XML tags in lower case.

Furthermore, XML is case sensitive. Always remember that <composer>, <composer> and <composer> are different kinds of tags in XML.

Tags should begin with either a letter, an underscore (_) or a colon (:) followed by some combination of letters, numbers, periods (.), colons, underscores, or hyphens (-) but no white space, with the exception that no tags should begin with any form of "xml". It is also a good idea to not use colons as the first character in a tag name even if it is legal. Using a colon first could be confusing.

The XML 1.0 standard does not limit the length of tag names, but  XML processors may limit the length of markup names.

In the next chapter we will have a look at an example XML file, which will then be analyzed in detail.


back to last pagenext page

 


Home : Tutorials : XML Tutorial

 

Copyright© 1998-2004 All Rights Reserved. No portion of this site may be reproduced or redistributed without prior written permission from VistaEdge Technologies

All registered trademarks appearing on this site are the property of their respective owners. Java is a trademark or registered trademark of Sun Microsystems, Inc. in the United States and other countries. This site is not connected to Sun Microsystems, Inc. and is not sponsored by Sun Microsystems, Inc.