Introduction to XML Kanda Runapongsa Dept. of Computer Engineering Khon Kaen University.

19
Introduction to XML Kanda Runapongsa ([email protected] ) Dept. of Computer Engineering Khon Kaen University

description

168493: XML and Web Services (II/2546) 3 What is XML? XML stands for eXtensible Markup Language The standard for data interchange on the Web XML is a text-based markup language Identify data using tags which are acted as markup Tags are surrounded by Example: Students

Transcript of Introduction to XML Kanda Runapongsa Dept. of Computer Engineering Khon Kaen University.

Page 1: Introduction to XML Kanda Runapongsa Dept. of Computer Engineering Khon Kaen University.

Introduction to XML

Kanda Runapongsa ([email protected])

Dept. of Computer EngineeringKhon Kaen University

Page 2: Introduction to XML Kanda Runapongsa Dept. of Computer Engineering Khon Kaen University.

168493: XML and Web Services (II/2546)

2

Outline What is XML? XML vs. HTML What are in XML Files?

Elements Attributes Entities Comments Processing Instructions

Page 3: Introduction to XML Kanda Runapongsa Dept. of Computer Engineering Khon Kaen University.

168493: XML and Web Services (II/2546)

3

What is XML? XML stands for eXtensible Markup

Language The standard for data interchange on

the Web XML is a text-based markup language

Identify data using tags which are acted as markup

Tags are surrounded by < and > Example:<To>Students</To>

Page 4: Introduction to XML Kanda Runapongsa Dept. of Computer Engineering Khon Kaen University.

168493: XML and Web Services (II/2546)

4

HTML vs. XML HTML was designed to display data but

XML was designed to describe (identify) data

Examples: HTML: display the text “Computer

Engineering” in bold<b>Computer Engineering</b>

XML: describe that “Computer Engineering” is a department<dept>Computer Engineering</dept>

Page 5: Introduction to XML Kanda Runapongsa Dept. of Computer Engineering Khon Kaen University.

168493: XML and Web Services (II/2546)

5

HTML vs. XML (Cont.) HTML tags are predefined but XML

tags are defined by the XML author The XML author uses any XML tags

that make sense for a given application

For applications that use the same XML data, they have to agree on the tag names they intend to use

HTML name tags are case insensitive but XML name tags are case sensitive

Page 6: Introduction to XML Kanda Runapongsa Dept. of Computer Engineering Khon Kaen University.

168493: XML and Web Services (II/2546)

6

Why XML? Simple and extensible License-free Platform independent International language support Read and edit XML using any

standard text-editing tool

Page 7: Introduction to XML Kanda Runapongsa Dept. of Computer Engineering Khon Kaen University.

168493: XML and Web Services (II/2546)

7

XML Usage Exchange data XML and B2B (Business to Business)

ebXML: Electronic Business using XML Share data Store data Create new languages

WML: Wireless Markup Language

Page 8: Introduction to XML Kanda Runapongsa Dept. of Computer Engineering Khon Kaen University.

168493: XML and Web Services (II/2546)

8

Outline What is XML? XML vs. HTML What are in XML Files?

Elements Attributes Entities Comments Processing Instructions

Page 9: Introduction to XML Kanda Runapongsa Dept. of Computer Engineering Khon Kaen University.

168493: XML and Web Services (II/2546)

9

A Sample XML Document<?xml version=“1.0” encoding=“ISO-8859-1”?

><Note>

<To>Students</To><From>Teacher</From><Course id=“168493”><Name>XML and Web Services</Name><Time>2:00-3:30 PM</Time><Place>Dept. of Computer Engineering</Place>

</Course></Note>

Page 10: Introduction to XML Kanda Runapongsa Dept. of Computer Engineering Khon Kaen University.

168493: XML and Web Services (II/2546)

10

Elements Represent a logical component of an XML

document Elements can contain

Other elements (sub-elements) Text (character data)

The boundary of each element: marked w/ a tag which Starts with < Ends with >

Example: <To>Students</To>

Page 11: Introduction to XML Kanda Runapongsa Dept. of Computer Engineering Khon Kaen University.

168493: XML and Web Services (II/2546)

11

Attributes Descriptive information attached to

elements Attributes are set inside the start tag

of an element Example: <Course id=“168493”> What are the difference between

elements and attributes? Containment Number of occurrences

Page 12: Introduction to XML Kanda Runapongsa Dept. of Computer Engineering Khon Kaen University.

168493: XML and Web Services (II/2546)

12

Entities Some characters are used to

markup text in an XML document <, >

To represent these characters There must be an alternative way

to represent them In XML, entities are used to

these special characters

Page 13: Introduction to XML Kanda Runapongsa Dept. of Computer Engineering Khon Kaen University.

168493: XML and Web Services (II/2546)

13

Entities for Special CharactersCharacters Entities< &lt;> &gt;& &amp;‘ &apos;“ &quot;

Page 14: Introduction to XML Kanda Runapongsa Dept. of Computer Engineering Khon Kaen University.

168493: XML and Web Services (II/2546)

14

Comments Comments begin with <!-- and

end with --> Comments can contain any data

except the literal string -- An XML processor is not required

to pass them along to an application

Page 15: Introduction to XML Kanda Runapongsa Dept. of Computer Engineering Khon Kaen University.

168493: XML and Web Services (II/2546)

15

Processing Instructions Give commands or information to

an application that is processing the XML data

Format:<?target instructions?> target is the name of the application

that is expected to do the processing instructions is a string of characters

that embodies the information or commands for the application to process

Page 16: Introduction to XML Kanda Runapongsa Dept. of Computer Engineering Khon Kaen University.

168493: XML and Web Services (II/2546)

16

CDATA Sections Instructs the parser to ignore

most markup characters Consider a source code listing in

an XML document. It might contain characters that the XML parser would ordinarily recognize as markup (< and & for example)

Page 17: Introduction to XML Kanda Runapongsa Dept. of Computer Engineering Khon Kaen University.

168493: XML and Web Services (II/2546)

17

CDATA Sections (Cont.) Example<![CDATA[*p = &q; b = (i <= 3); ]]> Between the start of the section, <!

[CDATA[ and the end of the section, ]]>, all character data is passed directly to the application

Page 18: Introduction to XML Kanda Runapongsa Dept. of Computer Engineering Khon Kaen University.

168493: XML and Web Services (II/2546)

18

Well-formed XML Documents

A document can only be well-formed if it obeys the syntax of XML

Requirement for well-formed documents Elements must have a closing tag Elements must be properly nested XML documents must have a root element Attribute values must always be quoted

Well-formed XML documents make it easier to process XML data

Page 19: Introduction to XML Kanda Runapongsa Dept. of Computer Engineering Khon Kaen University.

168493: XML and Web Services (II/2546)

19

Schema of XML Documents

Specify allowed XML elements and the relationships between these elements

Facilitate the validation and processing

Several XML Schema languages have been developed. DTD: Document Type Definition XML Schema