There are 3 types of software tools that one needs to use when working with XML files: text editors, Web browsers and validators. There are many alternatives within each type, but it appears to me that Dreamweaver 8 provides both the first and third tools and provides an easy preview link to the browser of my choice.
There are 7 different parts to a typical XML document:
- Prologs
- XML declarations
- Processing instructions
- Elements and attributes
- Comments
- CDATA sections
- Entities
This appears to be jargon, but it is essential to learn both the terms (and what they mean). This is the conceptual part of learning XML and is critical to understanding the procedures when one is using Dreamweaver 8. |
This diagram shows the 7 topics, organized as they should appear in an XML file:
1. XML declarations
An XML declaration is the first line of an XML file. This specifies the version of XML that is being used (use 1.0 rather than 1.1 as most browsers are not yet ready for 1.1).
The declaration should also include the encoding language used for the document. The default is UTF-8. Dreamweaver 8 uses ISO-8859-1.
Here is the first line of an XML file created automatically by Dreamweaver 8:
<?xml version="1.0" encoding="ISO-8859-1"?>
2. Comments
Comments can be inserted at any point in the file to provide additional explanatory or descriptive notes. They are valuable if more than one person is working on the file.
The text inside a comment is ignored by the XML processor.
A comment begins with <!-- and ends with -->
Example:
<!-- This is an example of a comment.-->
Here is an example of a very simple XML file:
<?xml version="1.0" encoding="ISO-8859-1"?>
<root>
<!-- This is an example of a comment. -->
</root>
The file begins with an XML declaration and then has beginning root tag. This is followed by all of the other XML code and ends with an ending root tag. The only actual code so far is a comment statement. |
3. Processing Instructions
A processing instruction provides additional information to the XML processor. The commands are processor dependent. For example most browsers recognize the following command as a way of linking a CSS stylesheet to an XML file:
<?xml-stylesheet type="text/css" href="filename.css"?>
This is usually the second line of an XML file and occurs before the root tag.
4. Creating Tags and Elements
A tag is simply a character string enclosed in < >.
A tag name should begin with a letter and is case-sensitive.
Every element should have both a beginning tag and an end tag.
e.g. <tag> ... </tag>
Every XML file should be well-formed. This means that all elements must be contained within a root element, and that the nesting is well-structured.
Example:
<?xml version="1.0" encoding="ISO-8859-1"?>
<?xml-stylesheet type="text/css" href="filename.css"?>
<root>
<!-- This is an example of a comment. -->
</root>
An XML attribute is a pair of words, separated by an = symbol. The first word is the name of the attribute and the second word (enclosed in "s) is the value of the attribute.
Example: height="10"
Attributes may occur within elements, XML declarations, and processing instructions.
5. CDATA sections
CDATA stands for character data whereas PCATA stands for parsed character data.
Here is the format for enclosing data that one does not want parsed by the XML processor:
<![CDATA[textual material involving special characters and formatting]]>
6. Entities
An entity is simply a data item such as a section of text or binary data.
Entity references are replaced by the entities they refer to by the XML processor.
Example: " will be replaced by the " symbol.
The material in this chapter covers the basic syntax of an XML file.
However it is also often important to provide information about the nature of the data that is stored within the XML file. This is done by means of a Document Type Definition (DTD) or an XML schema.
Then once one is confident that the XML file contains valid data, one can focus on how to display this data on various devices. This involves the use of Cascading Style Sheets (a CSS file) or other stylesheet conventions (an XSLT file - Extensible Stylesheet Language Transformation) |
QUIZ
1. What two character encodings are all XML processors supposed to implement?
UTF-8 and UTF-16
2. If you wanted to include the text data "This is a <message> element" in an element named <message>, how could you do it without confusing an XML processor?
<message>
<![CDATA[This is a <message> element]]>
</message>
3. What items can be contained in an XML prolog?
XML declaration, comments, and processing instructions.
4. What three attributes can appear in an XML declaration?
version, encoding method, standalone
5. What processing instructions are built into XML already?
none
|