XML
(Website Development)
Neeraj Kr. Gupta
Asstt. Prof.
IIMTEC, Meerut
XML Naming Rules for Elements
XML elements must follow these naming rules:
•Element names are case-sensitive.
•Element names can contain letters, digits, hyphens, underscores,
and periods.
•Element names cannot contain spaces.
•Element names must start with a letter or underscore.
•Element names cannot start with the letters xml (or XML, or Xml,
etc)
•Any name can be used, no words are reserved (except xml).
C. Empty Tags
D. Comments
E. Processing Instructions An XML file can also contain processing
instructions that give commands or information to an application
that is processing the XML data. Processing instructions have the
following format:
<?target instructions?>
Where the target is the name of the application that is expected to
do the processing, and instructions is a string of characters that
embodies the information or commands for the application to
process.
Viewing XML Files
An xml file can be viewed in all major browsers.
Don’t expect XML files to be displayed as HTML pages.
Create an xml file having following data :
<?xml version="1.0" encoding="UTF-8"?>
<CATALOG>
<CD>
<TITLE>Empire Burlesque</TITLE>
<ARTIST>Bob Dylan</ARTIST>
<COUNTRY>USA</COUNTRY>
<COMPANY>Columbia</COMPANY>
<PRICE>10.90</PRICE>
<YEAR>1985</YEAR>
</CD>
<CD>
<TITLE>Hide your heart</TITLE>
<ARTIST>Bonnie Tyler</ARTIST>
<COUNTRY>UK</COUNTRY>
<COMPANY>CBS Records</COMPANY>
<PRICE>9.90</PRICE>
<YEAR>1988</YEAR>
</CD>
</CATALOG>
Save the above created xml document by any name & having the
extension “.xml”.
Start any web browser & open the above created xml document.
You will get the following output :
Notice that an XML document will be displayed with color-coded root and
child elements. A plus (+) or minus sign (-) to the left of the elements can
be clicked to expand or collapse the element structure. To view the raw
XML source (without the + and - signs), select "View Page Source" or "View
Source" from the browser menu.
Why Does XML Display Like This?
XML documents do not carry information about how to display the data.
Since XML tags are "invented" by the author of the XML document, browsers
do not know if a tag like <table> describes an HTML table or a dining table.
Without any information about how to display the data, most
browsers will just display the XML document as it is.
Note : With CSS (Cascading Style Sheets) you can add display information to an
XML document.