Chapter 7 XML
Chapter 7 XML
Chapter 7 XML
Introduction to XML
Extensible Markup Language
We will learn:
• XML Introduction
• XML How to use
• XML Tree
• XML Syntax
• XML Elements
• XML Attributes
• XML and XSLT
What is XML
• XML stands for EXtensible Markup Language
• With XML, the author must define both the tags and the
document structure.
XML is Extensible
• Most XML applications will work as expected even if new data
is added (or removed).
• Imagine an application designed to display the original version
of note.xml (<to> <from> <heading> <data>).
• Then imagine a newer version of note.xml with added <date>
and <hour> elements, and a removed <heading>.
• The way XML is constructed, older version of the application
can still work:
XML is Extensible
XML Simplifies Things
14
XML Tree Structure
• XML documents are formed as element trees.
• An XML tree starts at a root element and branches from the root
to child elements.
• All elements can have sub elements (child elements):
• The terms parent, child, and sibling are used to describe the
relationships between elements.
• All elements can have text content (Harry Potter) and
attributes (category="cooking").
XML Syntax Rules
• XML documents must have a root element.
• All XML elements must have a closing tag.
• XML tags are case sensitive.
Incorrect
• Comments in XML
XML Syntax Rules
Entity References
• Some characters have a special meaning in XML.
Incorrect
Or
• The xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
points to the official W3C XSLT namespace. If you use this
namespace, you must also include the attribute
version="1.0".
How to transform XML into XHTML using XSLT?
• We want to transform the following XML document
("cdcatalog.xml") into XHTML:
How to transform XML into XHTML using XSLT?
• You need to create an XSL Style Sheet ("cdcatalog.xsl") with
a transformation template:
How to transform XML into XHTML using XSLT?
• Link the XSL style sheet to the XML document by adding the
XSL style sheet reference to your XML document
("cdcatalog.xml"):
How to transform XML into XHTML using XSLT?
• If you have an XSLT compliant browser, it will nicely
transform your XML into XHTML.
• The results: