Chapter 6 XML
Chapter 6 XML
Wollo University
Kombolcha Institute of Technology What is XML
College of Informatics
Department of Information System XML stands for eXtensible Markup Language.
A markup language is used to provide information
Introduction to Internet Programming I
about a document.
Chapter 6 Tags are added to the document to provide the extra
Introduction to Extensible Markup information.
HTML tags tell a browser how to display the
Language (XML) document.
XML tags give a reader some idea what some of the
Instructor: Habtamu Abate (M.Sc.) data means.
Email: [email protected]
1
XML documents are used to transfer data from one place to XML is text (Unicode) based.
another often over the Internet.
Takes up less space.
XML subsets are designed for particular applications.
Can be transmitted efficiently.
One is RSS (Rich Site Summary or Really Simple Syndication ).
It is used to send breaking news bulletins from one web site to One XML document can be displayed differently in
another. different media.
A number of fields have their own subsets. These include Html, video, CD, DVD,
chemistry, mathematics, and books publishing.
You only have to change the XML document in order to
Most of these subsets are registered with the W3Consortium
and are available for anyone’s use. change all the rest.
XML documents can be modularized. Parts can be
reused.
1
28-Jan-20
HTML tags have a fixed meaning and browsers Tags are enclosed in angle brackets.
know what it is. Tags come in pairs with start-tags and end-tags.
XML tags are different for different applications, Tags must be properly nested.
and users know what they mean. <name><email>…</name></email> is not allowed.
<name><email>…</email><name> is.
HTML tags are used for display. Tags that do not have end-tags must be terminated
XML tags are used to describe documents and data. by a ‘/’.
<br /> is an html example.
2
28-Jan-20
3
28-Jan-20
An XML document has a single root node. A well-formed document has a tree structure and
obeys all the XML rules.
The tree is a general ordered tree. A particular application may add more rules in either
A parent node may have any number of children. a DTD (document type definition) or in a schema.
Child nodes are ordered, and may have siblings. Many specialized DTDs and schemas have been
created to describe particular areas.
Preorder traversals are usually used for getting
These range from disseminating news bulletins (RSS)
information out of the tree. to chemical formulas.
DTDs were developed first, so they are not as
comprehensive as schema.
4
28-Jan-20
A DTD describes the tree structure of a document <!ELEMENT address (name, email, phone, birthday)>
and something about its data. <!ELEMENT name (first, last)>
There are two data types, PCDATA and CDATA. <!ELEMENT first (#PCDATA)>
PCDATA is parsed character data. <!ELEMENT last (#PCDATA)>
CDATA is character data, not usually parsed.
<!ELEMENT email (#PCDATA)>
<!ELEMENT phone (#PCDATA)>
A DTD determines how many times a node may
<!ELEMENT birthday (year, month, day)>
appear, and how child nodes are ordered.
<!ELEMENT year (#PCDATA)>
<!ELEMENT month (#PCDATA)>
<!ELEMENT day (#PCDATA)>
5
28-Jan-20
XSLT
Explanation of Example Schema
Extensible Stylesheet Language Transformations
<?xml version="1.0" encoding="ISO-8859-1" ?>
ISO-8859-1, Latin-1, is the same as UTF-8 in the first 128 characters.
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">
XSLT is used to transform one xml document into
www.w3.org/2001/XMLSchema contains the schema standards. another, often an html document.
<xs:element name="address">
The Transform classes are now part of Java 1.4.
<xs:complexType>
This states that address is a complex type element. A program is used that takes as input one xml
<xs:sequence> document and produces as output another.
This states that the following elements form a sequence and must come in the
order shown. If the resulting document is in html, it can be viewed
<xs:element name="name" type="xs:string"/> by a web browser.
This says that the element, name, must be a string.
6
28-Jan-20
25 Question???
Practice:
Lab Exercise # 1,2 and3