| |
| Overview |
| |
| In this chapter you will learn : |
- How to write an XML document?
- What are the important parts of an XML program?
- What is root element?
- What are empty elements?
|
A sample XML document for a web page is shown below. It contains all the important parts that are usually contained in XML documents.
| Example |
<?xml version ="1.0"?>
<My.page>
<head>
<title> My home page </title>
<header source = "imagehead.gif "/>
</head>
<body>
<main.title> Welcome to my home page </main.title>
<rule/>
<text>
<para>
SORRY! This page is still under construction. Visit this site soon.
</para>
</text>
</body>
<footer source= imagefoot.gif "/>
</My.page> |
XML Declaration
[i.e., <? xml version = "1.0" ?>]
-
The XML declaration identifies what follows it as XML code.
-
It states which version of the XML standard the code compiles with, and it specifies whether the document can be treated as a stand-alone document or whether DTD ( Document Type Definition, [defined later in the tutorial] ) must also be retrieved in order to make full sense of the contents.
-
The XML declaration is a processing instruction (identified by the ? at its start and end).
| Note |
| The XML declaration is not strictly compulsory. |
The Root Element
[i.e., from < My.page> to </ My.page> ]
-
Each XML document must have only one root element, and all the other elements must be completely enclosed in that element.
-
In XML, an element normally consists of 3 things :
-
a start tag.
-
content (either text or other elements ).
-
an end tag.
-
The name you use in the element start tag must exactly match the name you use in the end tag.
- XML is case sensitive, recognizing the difference between uppercase letters and lowercase letters.
An Empty Elements
[i.e., < rule/ > ]
Empty elements are a special case in XML.
-
XML requires you to be much more explicit when dealing with empty elements.
-
To do so, there is a special empty tag close delimiter, /> , as in the following :
<empty-element />
- You can also use an end tag instead of the special empty tag close delimiter. The element declaration :
< graphic source= " image.gif "/> is therefore interchangeable with
< graphic source= " image.gif ">.............</ graphic>
Attributes
[i.e., <header source="imagehead.gif"/> , <footer source = 'imagefoot.gif"/>]
-
Element tags can include one or more optional or mandatory attributes.
-
Attributes can only be specified in the element start tag.
-
The syntax for specifying an attribute is :
| Syntax |
| <attribute.type.name attribute.name = "attribute.value" > |
| Example |
| < fruit taste = "sharp" > |
-
XML deals with multiple declaration of attributes in a unique manner. If an element appears once with one set of attributes and then appears again with a different set of attributes, the two sets of attributes are merged.
-
The first declaration of an attribute for a particular element is the only one that counts, and any other declarations are ignored.
| |
| Summary |
| |
In this chapter you have learnt:
- About XML’s interaction with the data.
- How XML is used to share information and exchange information?
- How XML stores the data inside HTML ?
|
| |
| Review Questions |
| |
Fill in the Blanks
- The first line of an XML program is known as XML ---------.
- The root element is also known as --------- element.
- An element normally consists of three things, i.e., ------- tag, ------- and end tag.
- An element with no content in it is called -------- element.
- ------- are specified in the element start tag.
Solutions
- declaration
- parent
- start tag, content
- empty
- Attributes
True or False
- XML declaration is compulsory.
- There can be more than one root elements.
- XML is case sensitive.
- An empty element can have contents in it.
- Attributes are compulsory to specify in the element.
Solutions
- False
- False
- True
- False
- False
|
| |
| |
| What's Next |
The next chapter will acquaint you with the basic concepts of XML elements and attributes. The chapter will further elucidate how to name elements and attributes and various advantages and disadvantages of using elements and attributes.
Hop over to the next chapter to get an XML elements and attributes close-up.
|
| |
|
| |
|