Sei sulla pagina 1di 23

<title>XML Overview</title>

<subtitle>eXtensible MarkupLanguage</subtitle>
<presenter>Hirak Dasgupta</presenter> <email></email> <company> Centre For Railway Information Systems</company> <date>06 September 2012</date>

What is a Markup Language?

Marking up text is a methodology for encoding data with information about itself.

Two Crucial Points

For markups to transmit useful information about data to a pool of users...

a standard must be in place to define what a valid markup is - In the example above, markup is defined as a bit of red ink atop text. a standard must be in place to define what markup means - In the example above, a red highlight means the highlighted text represents an important point.

HTML is one of the famous computer markup systems. HTML defines a set of tags that associate formatting rules with bits of text. Documents which have been marked up are read by an HTML processing application (a web browser for example) that knows how to display the text according to the rules.

How XML evolved? I

Using standard HTML, a developer might use something like the following:

How XML evolved? II

Some particularly serious problems with HTML

The GUI is embedded in the data. Searching for information in the data is tough. The data is tied to the logic and language of HTML. Fixed set of predefined tags

All such problems result into the evolution of XML which helps in complete separation of Data layer and presentation layer

XML: Breaking the Tag Monopoly

Like HTML, XML (also known as Extensible Markup Language) is a markup language which relies on the concept of rule-specifying tags and the use of a tagprocessing application that knows how to deal with the tags. XML is far more powerful than HTML. This is because of the "X". XML is "eXtensible". XML is a meta-markup language which allows you to define an infinite number of markup languages based upon the standards defined by XML. XML Code


XML stands for eXtensible Markup Language
HTML is used to mark up text so it can be displayed to users HTML describes both structure (e.g. <p>, <h2>, <em>) and appearance (e.g. <br>, <font>, <i>) HTML uses a fixed, unchangeable set of tags XML is used to mark up data so it can be processed by computers XML describes only content, or meaning

In XML, you make up your own tags



HTML and XML look similar, because they are both SGML languages (SGML = Standard Generalized Markup Language)

Both HTML and XML use elements enclosed in tags (e.g. <body>This is an element</body>) Both use tag attributes (e.g., <font face="Verdana" size="+1" color="red">) Both use entities (&lt;, &gt;, &amp;, &quot;, &apos;) HTML is defined in SGML XML is a (very small) subset of SGML

More precisely,


HTML is for humans

HTML describes web pages You dont want to see error messages about the web pages you visit Browsers ignore and/or correct as many HTML errors as they can, so HTML is often sloppy
XML describes data The rules are strict and errors are not allowed

XML is for computers

In this way, XML is like a programming language

Current versions of most browsers can display XML


XML-related technologies

DTD (Document Type Definition) is used to define legal XML tags and their attributes for particular purposes XSLT (eXtensible Stylesheet Language Transformations) is used to translate from one form of XML to another and also convert XML data into web pages DOM (Document Object Model) and SAX (Simple API for XML are APIs for XML parsing


Example XML document

<?xml version="1.0"?> <weatherReport> <date>7/14/97</date> <city>North Place</city>, <state>NX</state> <country>USA</country> High Temp: <high scale="F">103</high> Low Temp: <low scale="F">70</low> Morning: <morning>Partly cloudy, Hazy</morning> Afternoon: <afternoon>Sunny &amp; hot</afternoon> Evening: <evening>Clear and Cooler</evening> </weatherReport>
From: XML: A Primer, by Simon St. Laurent

Overall structure

An XML document may start with one or more processing instructions (PIs) or directives:
<?xml version="1.0"?> <?xml-stylesheet type="text/css" href="ss.css"?>

Following the directives, there must be exactly one root element containing all the rest of the XML:
<weatherReport> ... </weatherReport>


XML building blocks

Aside from the directives, an XML document is built from:

elements: high in <high scale="F">103</high> tags, in pairs: <high scale="F">103</high> attributes: <high scale="F">103</high> entities: <afternoon>Sunny &amp; hot</afternoon> character data, which may be:

parsed (processed as XML)--this is the default unparsed (all characters stand for themselves)


Well-formed XML

Every element must have both a start tag and an end tag, e.g. <name> ... </name> But empty elements can be abbreviated: <break />. XML tags are case sensitive XML tags may not begin with the letters xml, in any combination of cases Elements must be properly nested, e.g. not <b><i>bold and italic</b></i> Every XML document must have one and only one root element The values of attributes must be enclosed in single or double quotes, e.g. <time unit="days"> Character data cannot contain < or &


Five special characters must be written as entities:

&amp; for &lt; for &gt; for &quot; for &apos; for & < > " ' (almost always necessary) (almost always necessary) (not usually necessary) (necessary inside double quotes) (necessary inside single quotes)

These are the only predefined entities in XML


XML declaration

The XML declaration looks like this: <?xml version="1.0" encoding="UTF-8" standalone="yes"?>

The XML declaration is not required by browsers, but is required by most XML processors (so include it!) If present, the XML declaration must be first--not even whitespace should precede it Note that the brackets are <? and ?> version="1.0" is required (this is the only version so far) encoding can be "UTF-8" (ASCII) or "UTF-16" (Unicode), or something else, or it can be omitted standalone tells whether there is a separate DTD



By default, all text inside an XML document is parsed You can force text to be treated as unparsed character data by enclosing it in <![CDATA[ ... ]]> Any characters, even & and <, can occur inside a CDATA Whitespace inside a CDATA is (usually) preserved The only real restriction is that the character sequence ]]> cannot occur inside a CDATA CDATA is useful when your text has a lot of illegal characters (for example, if your XML document contains some HTML text)


Valid XML

You can make up your own XML tags and attributes, but...

...any program that uses the XML must know what to expect!

A DTD (Document Type Definition) defines what tags are legal and where they can occur in the XML XML is well-structured if it follows the rules given earlier In addition, XML is valid if it declares a DTD and conforms to that DTD A DTD can be included in the XML, but is typically a separate document Errors in XML documents will stop XML programs


Why XML is used? I

Simplicity XML is easy to understand. You create the tags and overall set up of your document. What could be simpler than that? When writing a page in XML, the element tags are your own creation. You are free to develop the system based on your needs. Organization XML allows you to build your platform by segmenting the design process. Data sits on one page, and formatting rules stay on another. If you have a general idea of what information you need to produce, you can write the data page first then work on the design. XML allows you to produce the site in stages and stay organized in the process. 19

Why XML is used? II

Accessibility With XML you compartmentalize your work. Separating data makes it accessible when changes are needed. Standardization XML is an international standard. This means that anyone in the world is likely to have the ability to view your document. Multiple Applications You can make one data page and use it over and over again. This means if you are cataloging inventory, you only do it once. You can create as many display pages as you want for that data.

Why XML is used? III

XML Simplifies Platform Changes XML is Used to Create New Internet Languages
A lot of new Internet languages are created with XML. Here are some examples: XHTML WSDL for describing available web services WAP and WML as markup languages for handheld devices RSS (Really Simple Syndication) languages for news feeds SMIL(Synchronized Multimedia Integration Language) for describing multimedia for the web

Disadvantages of XML

XML requires a processing application No XML browsers on the market yet XML documents must either be converted into HTML before distribution or converting it to HTML on-the-fly by middleware


<End>Thank You</End>