Slides 2-5 — the definition, the comparison with HTML, and the four advantages.

Overview (slide 2)

XML stands for Extensible Markup Language. It is derived from SGML (Standard Generalized Markup Language) and it is a text-based markup language.

PropertyMeaning
Platform-independent the same file is meaningful on Windows, Linux and macOS
Language-independent Java, C#, Python and PHP all read the same file
Carries data XML stores and transports data — it does not display it
That last row is the whole reason XML exists and the reason it sits next to JSP in this topic. An HTML file is a finished picture; an XML file is the raw material. To see XML you must supply something that turns it into a picture — a browser's built-in XML viewer, an XSL stylesheet, or the JSP page you are about to write.

What is XML? (slide 3)

XML is a markup language like HTML which is used to store and transport data. It is self-descriptive: the document contains the sender's information, the receiver's information, a heading and a message body.

“The XML does not DO anything — it is just information wrapped in tags.”

Why do we need it? Because the structure of the data is embedded with the data, so there is no need to pre-build the structure to store it — XML understands its own structure. The document is well-formed and properly marked up.

“Well-formed” is a precise term, not a compliment. It means every element has a closing tag, tags nest properly, attributes are quoted, and there is exactly one root element. XML has no optional end tags and no ‘void’ elements the way HTML does. A browser that meets a not-well-formed document refuses to display it and tells you where the error is — compare that with HTML, which silently renders whatever it can.

XML versus HTML (slide 4)

HTML XML
Syntax and semantics predefined by the specification the author defines both
Purpose create a visible presentation for the user store and transport data
Well-formed not required required
Tags predefined (<p>, <table>) user-defined (<book>, <name>)
Who displays it the browser, on its own needs a stylesheet or a program — see s8-05

“Predefined” is the difference that matters in practice. HTML tells the browser what <h1> means; XML makes the browser ask what is a <price>? — and the answer has to come from somewhere. That somewhere is XSLT or your own code.

Advantages of XML (slide 5)

“Unicode-based” is worth a moment. A single XML file can hold English, Telugu, Japanese and emoji in one document with no escape sequences and no “which code page is this?” guesswork — which is why the declaration at the top of every file in this session is <?xml version="1.0" encoding="UTF-8"?>. The encoding part is not decoration; it tells the parser how to read the bytes. Change it to something the file is not actually in and the parse fails.

A taste of what well-formed means

<?xml version="1.0" encoding="UTF-8"?>
<note>
    <to>ZARA</to>
    <from>NUHA</from>
    <body>Books are due on Friday</body>
</note>
RuleShown above by
an XML declaration first<?xml ... ?>
exactly one root element<note>
every start tag is closed</note>
tags nest in pairsthe four children sit inside <note>
the structure is the descriptionno DTD or schema is needed to know that this is a note addressed to somebody

The books.xml example →

← Back to the example index