XML
XML
MARKUP
LANGUAGE)
WHAT IS XML?
The first thing we need to understand about XML is that it isn’t just
another markup language like the Hypertext Markup language (HTML).
These languages define a fixed set of tags that describe a fixed number
of elements. If the markup language we use doesn’t contain the tag we
need—we are out of luck. We can wait for the next version of the
markup
Language hoping that it includes the tag we need; but then we are
really at the mercy of what the vendor chooses to include. XML,
however, is a meta-markup language. It’s a language in which we make
up the tags we need as we go along. These tags must be organized
according to certain general principles, but they’re quite flexible in their
meaning.
The difference Between XML and HTMLS
XML looks similar to HTML. Like XML, HTML is also a markup language. In
fact, HTML stands for Hypertext Markup Language. Markup languages
are used for describing how a document’s contents should be
interpreted.
XML was designed to transport and store data, with focus on what data
is.
HTML was designed to format and display data.
HTML includes over 100 pre-defined tags to allow the author to specify
how each piece of content should be presented to the end user.
XML
XML allows us to create our own tags to describe the data between them.
It is not interested in how the data is presented. The main focus is
ensuring that the data is well organized within descriptive tags. This is
because while we can view XML documents form. XML viewers interpret
the document so it will display the XML documents using any styles that
have been applied using CSS. It will also warn us of something doesn’t
look right, or if it doesn’t validate correctly.
Most modern browsers include XML support, so it’s quite possible that
our own the browser is able to display the contents of XML files.
The XML file is opened in same way as any other file in the browser. If it
is a local file the full path can be typed into the address bar. Otherwise, if
it’s available over the web, we can type the URL into the address bar.
NOTEPAD
We can use a text editor such as Notepad to create or view a simple
XML files. Here what this XML file looks like in notepad.
INTERNET EXPLORER
If the XML document contains an error, the XML viewer will display a
message indicating the error. In this file, there is an error.
<tutorials>
<tutorial>
<name> XML tutorial</name>
<url>http://www.quackit.com/xml/tutorial</url>
</tutorial>
</Ttutorials>
The tags below (like <to> and <from>) are not defined in any XML
standard. These tags are “invented” by the author of the XML
document. This is because XML language has no predefined tags.
Example:
<note>
<to>john </to>
<from>ravi </from>
<heading>Reminder</heading>
<body>Don’t forget me this weekend</body>
</note>
The note above is self descriptive. It has the senders and receivers
information, it also has a heading and a message body.
The XML allows the author to define his own tags and his own
document structure. The tags used in HTML are predefined. HTML
documents can only use tags defined in the HTML standard (like <p>,
<b>, etc…).
Once we’ve typed the preceding code, save the document in a file
called hello.xml, HelloWorld.xml, MyFirstDocument.xml, or some other
name. The three-letter extension .xml is fairly standard. However, do
make sure that we save it in plain text format, and not in the native
format of some word processor like WordPerfect or Microsoft Word.
XML TREE
<child>
<subchild>.....</subchild>
</child>
</root>
The terms parent, child, and sibling are used to describe the
relationships between elements. Parent elements have children.
Children on the same level are called siblings (brothers or sisters).All
elements can have text content and attributes.
XML Elements
An element can contain other elements, simple text and can also have
attributes.
<bookstore>
<title>Harry Potter</title>
<author>J K.
Rowling</author>
<year>2005</year>
<price>29.99</price>
</bookstore>
In the example above, <bookstore> have element contents because
they contain other elements. <author> has text content because it
contains text.
XML Attributes
An Example:
<book category="CHILDREN">
<title>Harry Potter</title>
<author>J K. Rowling</author>
<year>2005</year>
<person
sex="female">
Or like this:
<person
sex='female'>
If the attribute value itself contains double quotes we can use single
quotes, like in this example:
<gangster name="George"Shotgun"
Ziegler">
Until then, one good rule of thumb is that the data itself should be
stored in
elements. Information about the data (meta-data) should be stored in
attributes.
And when in doubt, put the information in the elements.
If all tags were stripped from the document along with all the attributes,
the basic information should still be present. Attributes are good places
to put ID numbers, references and other information not directly or
immediately relevant to the reader.
<person sex="female">
<firstname>Anna</firstnam
e>
<lastname>Smith</lastnam
e>
</person>
<person>
<sex>female</sex>
<firstname>Anna</firstnam
e>
<lastname>Smith</lastnam
e>
</person>
There are no rules about when to use attributes and when to use
elements. In XML we can avoid using attributes. Use elements instead.
Attributes are difficult to read and maintain. Use elements for data. Use
attributes for information that is not relevant to the data.
In HTML, we will often see elements that don't have a closing tag:
<p>This is a paragraph
In XML, it is illegal to omit the closing tag. All elements must have a
closing tag:
<p>This is a paragraph</p>
Naturally, it’s better to pick tags that more closely reflect the meaning
of the information they contain. Many disciplines like math and
chemistry are working on creating industry standard tag sets. These
should be used when appropriate.
XML tags are case sensitive. With XML, the tag <Letter> is different
from the tag <letter>.Opening and closing tags must be written with
the same case:
<Message>This is incorrect</message>
<message>This is correct</message>
In the example above, "Properly nested" simply means that since the
<i> element is opened inside the <b> element, it must be closed
inside the <b> element.
XML documents must contain one element that is the parent of all
other elements. This element is called the root element.
<root>
<child>
<subchild>.....</subchild>
</child>
</root>
In XML the attribute value must always be quoted. Study the two XML
documents below. The first one is incorrect, the second is correct:
<note date=12/11/2007>
<to>Tove</to>
<from>Jani</from>
</note>
<note date="12/11/2007">
<to>Tove</to>
<from>Jani</from>
</note>
The error in the first document is that the date attribute in the note
element is not quoted.
7. Entity References
7. COMMENT LINES
Each language has comment lines just to explain about the program. In
XML, comment lines are written like this.
USES OF XML
With XML, data can be stored in separate XML files. This way we can
concentrate on using HTML for layout and display, and be sure that
changes in the underlying data will not require any changes to the
HTML.
XML data is stored in plain test format. This provides a software and
hardware independent way of storing data.
This makes it much easier to create data that different applications can
share.
Exchanging data as XML greatly reduces this complexity, singe the data
can be read by different incompatible applications.
Different applications can access our data, not only in HTML pages, but
also from XML data sources.
With XML, our data can be available to all kinds of “reading machines”
(Handheld computers, voice machines, news feed, etc) and make it
more available for blind people with other disabilities.
Related Technologies
Mozilla 5.0 and Internet Explorer 5.0 are the first Web browsers to
provide some support for XML, but it takes about two years before most
users have upgraded to a particular release of the software. So we’re
going to need to convert our XML content into classic HTML for
some time to come. Therefore, before we jump into XML, we should be
completely comfortable with HTML.
CSS, initially designed for HTML, defines formatting properties like font
size, font family, font weight, paragraph indentation, paragraph
alignment, and other styles that can be applied to particular elements.
For example, CSS allows HTML documents to specify that all H1
elements should be formatted in 32 point centered Helvetica bold.
It’s easy to apply CSS rules to XML documents. We simply change the
names of the tags we’re applying the rules to. Mozilla 5.0 directly
supports CSS style sheets combined with XML documents, though at
present, it crashes rather too frequently.
Furthermore, they can choose the style to use not just based on the
tag, but also on the contents and attributes of the tag, on the position
of the tag in the document relative to other elements, and on a variety
of other criteria.
CSS has the advantage of broader browser support. However, XSL is far
more flexible and powerful, and better suited to XML documents
BENIFITS
• Simplicity
Information coded in XML is easy to read and understand, plus
it can be processed easily by computers.
• Extensibility
There is no fixed set of tags. New tags can be created as they
are needed.
• Self-description
In traditional databases, data records require schemas set up
by the database administrator. XML documents can be stored
without such definitions, because they contain meta data in
the form of tags and attributes.
By
R.Saranya
S.Sahira