What is XML?
XML is an eXtensible Markup Language.
It is based on Standard Generalized Markup Language (SGML).
XML is HTML - presentation tags + your own custom tags.
With XML we can invent our own tags.
XML is a meta-language for defining other languages.
XML is a semi structured data model.
XML is not a data model but just an exchange syntax
XML is the ASCII of the Web.
XML has reinvented many Computer Science ideas.
XML has no mechanism to specify the format for presenting data to the user.
An XML document resides in its own file with an ‘.xml’ extension.
The Basic Rule
XML is case sensitive,
All start tags must have end tags.
Elements must be properly nested.
XML declaration is the first statement.
Every document must contain a root element.
Attribute values must have quotation marks.
Certain characters are reserved for parsing.
Why XML is used?
XML Separates Data from HTML:
If we need to display dynamic data in our HTML document, it will take a lot of work to edit the HTML each time the data changes.
With XML, data can be stored in separate XML files.
This way you 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 Simplifies Data Transport:
Exchanging data as XML greatly reduces this complexity, since the data can be read by different incompatible applications.
XML Simplifies Platform Changes:
XML data is stored in text format. This makes it easier to expand or upgrade to new operating systems, new applications, or new browsers without losing data.
XML Simplifies Data Sharing:
XML data is stored in plain text format. This provides a software and hardware independent way of storing data.
This makes it much easier to create data that can be shared by different applications.
XML Specification
XML 1.0:
Defines the syntax of XML.
XPointer, XLink:
Defines a standard way to represent links between resources.
XSL:
Defines the standard stylesheet language for XML.
Difference between XML and HTML
XML is not a replacement for HTML.
XML and HTML were designed with different goals.
XML was designed to describe data and to focus on what data is, while HTML was designed to display data and to focus on how data looks.
HTML is about displaying information, XML is about describing information.
XML Elements
An XML element is everything from (including) the element's start tag to (including) the element's end tag.
An element can contain:
Other elements
Text
Attributes
Or a mix of all of the above
XML Attributes
XML attributes are normally used to describe XML elements, or to provide additional information about elements.
From HTML we can remember this construct:
<IMGSRC="a.gif">
In this HTML example SRC is an attribute to the IMG element.
The SRC attribute provides additional information about the element.
Writing XML
XML Comments:
Comments can be put anywhere in an XML document.
Comments are useful for
Explaining the structure of an XML document.
Commenting out parts of the XML during development and testing.
Comments are not elements and do not have an end tag.
The blanks after “<! –- ”and before “-- >” are optional.
The character sequence cannot occur in the comment.
The closing bracket must be “-- >”
Comments are not displayed by browsers, but can be seen by anyone who looks at the source code.
XML Tags:
The tags used in XML, as well as being very similar in construction to HTML, also look like HTML tags.
They are formed by a word (or a number of words) enclosed inside <> and </> signs.
For example the <font></font> tag in HTML.
XML tags are not pre-defined like HTML tags.
An example could be the XML tag <message> and the end tag </message> which could be used to enclose an e-mail message stored on a web based e-mail system.
Example:
<?xmlversion="1.0"encoding="utf-8"?>
<note>
<header>
<to>name</to>
<from>name </from>
<subject>Comments on XML </subject>
<heading>Real Simple Code</heading>
<body>On The Go Learning and References</body>
<header>
</note>
Why XML is Important?
Plain Text:
Easy to edit.
Useful for storing small amounts of data.
Possible to efficiently store large amounts of XML data through an XML front end to a database.
Data Identification:
Identify what kind of data you have.
Can be used in different ways by different applications.
Stylability:
Inherently style-free.
XSL---eXtensible Stylesheet Language.
Different XSL formats can then be used to display the same data in different ways.
Linkability -- XLink and XPointer:
Simple unidirectional hyperlinks.
Two-way links.
Multiple-target links.
“Expanding” links.
Easily Processed:
Regular and consistent notation.
Vendor-neutral standard.
XML Applications
XML can be used to Store Data.
XML can Separate Data from HTML.
XML is used to Exchange Data.
XML can be used to create new Languages.
XML-related Technologies
DTD (Document Type Definition) and XML Schemas are used to define legal XML tags and their attributes for particular purposes.
CSS (Cascading Style Sheets) describes how to display HTML or XML in a browser.
XSLT (eXtensible Stylesheet Language Transformations) and XPath are used to translate from one form of XML to another.
DOM(Document Object Model), SAX (Simple API for XML, and JAXP (Java API for XML Processing) are all APIs for XML parsing.
XML Summary
XML is a self-descriptive language.
XML is a powerful language to describe structure data for web application.
XML is currently applied in many fields.
Many vendors support XML.