introduction to xml - khon kaen universitykrunapon/courses/188371/slides/intro2xml.pdf · web...

50
1 Introduction to XML Asst. Prof. Dr. Kanda Runapongsa Saikaew Dept. of Computer Engineering Khon Kaen University http://gear.kku.ac.th/~krunapon/xmlws

Upload: others

Post on 11-Jun-2020

5 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: Introduction to XML - Khon Kaen Universitykrunapon/courses/188371/slides/intro2xml.pdf · Web Services " XML data is exchanged between service provider & service requester " RSS,

1

Introduction to XML Asst. Prof. Dr. Kanda Runapongsa Saikaew

Dept. of Computer Engineering

Khon Kaen University

http://gear.kku.ac.th/~krunapon/xmlws

Page 2: Introduction to XML - Khon Kaen Universitykrunapon/courses/188371/slides/intro2xml.pdf · Web Services " XML data is exchanged between service provider & service requester " RSS,

2

Topics p What is XML? p Why XML? p Where does XML come from? p Where is XML being used

today? p What is going on standards

front?

Page 3: Introduction to XML - Khon Kaen Universitykrunapon/courses/188371/slides/intro2xml.pdf · Web Services " XML data is exchanged between service provider & service requester " RSS,

3

What is XML? (1/2)

<?xml version=“1.0”?>

<nation id=“th”>

<name>Thailand</name>

<location>Southeast Asia

</location>

</nation>

Page 4: Introduction to XML - Khon Kaen Universitykrunapon/courses/188371/slides/intro2xml.pdf · Web Services " XML data is exchanged between service provider & service requester " RSS,

4

What is XML? (2/2) p XML stands for Extensible Markup

Language

p It becomes the standard for data interchange on the Internet

p XML is a text-based markup language n  Encode the meaning of data by using tags which are

acted as markup

n  Tags are surrounded by < and >

n  Example: <Nationality>Thai</Nationality>

p It is also a meta-markup language

Page 5: Introduction to XML - Khon Kaen Universitykrunapon/courses/188371/slides/intro2xml.pdf · Web Services " XML data is exchanged between service provider & service requester " RSS,

5

An XML Document in Text Editor

Page 6: Introduction to XML - Khon Kaen Universitykrunapon/courses/188371/slides/intro2xml.pdf · Web Services " XML data is exchanged between service provider & service requester " RSS,

6

Markup Language p Used to markup data

n Methodology for encoding data with some information

p Examples n Yellow highlighter on a string of text as

emphasizer p Example: Many people view Thai as friendly

people

n Comma between pieces of data as separator p Example: People need food, clothes, medicine,

and house

Page 7: Introduction to XML - Khon Kaen Universitykrunapon/courses/188371/slides/intro2xml.pdf · Web Services " XML data is exchanged between service provider & service requester " RSS,

7

XML: Markup Language by W3C

Page 8: Introduction to XML - Khon Kaen Universitykrunapon/courses/188371/slides/intro2xml.pdf · Web Services " XML data is exchanged between service provider & service requester " RSS,

8

XML, HTML, and SGML p XML is a markup language defined by the

World Wide Web Consortium (W3C, www.w3c.org)

p Markup languages describe the way the content of the document should be interpreted

p The markup language that most people know is HTML

p Both HTML and XML are defined based on SGML (Standard Generalized Markup Language)

Page 9: Introduction to XML - Khon Kaen Universitykrunapon/courses/188371/slides/intro2xml.pdf · Web Services " XML data is exchanged between service provider & service requester " RSS,

9

SGML p SGML is used for documents in many

fields, such as Aerospace, Semiconductor, and Publishing

p Several barriers prevented SGML over the Web n Complex and unstable software

n Obstacles to interchange of SGML data

n No widely supported style sheets

Page 10: Introduction to XML - Khon Kaen Universitykrunapon/courses/188371/slides/intro2xml.pdf · Web Services " XML data is exchanged between service provider & service requester " RSS,

10

HTML p The most popular markup language

n  In 1998, Google search 28 million pages n  In 2005, Google search 8 billion pages n  In 2008, Google search 1 trillion pages

p Designed for presentation for data n Examples: <html>, <head>, <body>, <title>

p HTML documents are processed by HTML processing application (Browser)

Page 11: Introduction to XML - Khon Kaen Universitykrunapon/courses/188371/slides/intro2xml.pdf · Web Services " XML data is exchanged between service provider & service requester " RSS,

11

View an XML Document with Firefox Browser

Page 12: Introduction to XML - Khon Kaen Universitykrunapon/courses/188371/slides/intro2xml.pdf · Web Services " XML data is exchanged between service provider & service requester " RSS,

12

View an XML Document with Internet Explorer Browser

Page 13: Introduction to XML - Khon Kaen Universitykrunapon/courses/188371/slides/intro2xml.pdf · Web Services " XML data is exchanged between service provider & service requester " RSS,

13

Strengths of HTML p Easy to implement and author

n Small number of tags

n Simple relationship between tags

n Syntax-checking is very forgiving

n Limited number of formats possible

n Viewers can be small and simple

p HTML trades power for ease of use

Page 14: Introduction to XML - Khon Kaen Universitykrunapon/courses/188371/slides/intro2xml.pdf · Web Services " XML data is exchanged between service provider & service requester " RSS,

14

Weaknesses of HTML (1/2) p Fixed set of tags

n Not user extensible p Dependency to “markup language”

definition process

n Dependency to vendors p Vendor proprietary tags

p Implementation not in sync § Netscape browser vs. Internet Explorer browser

p Predefined semantics for each tag

p Predefined data structure

Page 15: Introduction to XML - Khon Kaen Universitykrunapon/courses/188371/slides/intro2xml.pdf · Web Services " XML data is exchanged between service provider & service requester " RSS,

15

Weaknesses of HTML (2/2) p No formal validation

p Does not support semantic search

p Based on solely on appearance (rendering) NOT on content

p Formatting too simple n Limited control

p Cannot process complex documents

p Have no document structure to enable automation

Page 16: Introduction to XML - Khon Kaen Universitykrunapon/courses/188371/slides/intro2xml.pdf · Web Services " XML data is exchanged between service provider & service requester " RSS,

16

What We Cannot Do with HTML p We cannot create our own tags

that are meaningful for each application

p We cannot have the way to specify a set of data that everyone agrees upon

p We cannot change shared data easily with minimal effort

Page 17: Introduction to XML - Khon Kaen Universitykrunapon/courses/188371/slides/intro2xml.pdf · Web Services " XML data is exchanged between service provider & service requester " RSS,

17

The Purpose of XML p  Easy for information to be

reused, interchanged, and automated

p  Deliver information on the Web

p  Let users design their own markup language

p  Could drive arbitrarily complex distributed processes

Page 18: Introduction to XML - Khon Kaen Universitykrunapon/courses/188371/slides/intro2xml.pdf · Web Services " XML data is exchanged between service provider & service requester " RSS,

18

Key Features of XML

p Extensibility

p Media and Presentation independence n Separation of contents from

presentation

p Structure

p Validation

Page 19: Introduction to XML - Khon Kaen Universitykrunapon/courses/188371/slides/intro2xml.pdf · Web Services " XML data is exchanged between service provider & service requester " RSS,

19

Extensibility (1/2) p XML is Meta-markup language

p You define your own markup languages (tags) for your own problem domain

p Infinite number of tags can be defined n Need for domain-specific standards

n XSLT

Page 20: Introduction to XML - Khon Kaen Universitykrunapon/courses/188371/slides/intro2xml.pdf · Web Services " XML data is exchanged between service provider & service requester " RSS,

20

Extensibility (2/2) p Tags can be more than formatting

n Semantics data representation n Business rules

p ebXML n Data relationship

p EJB 2.0 Container Managed Persistence

n Formatting p XSL

n Anything you want

Page 21: Introduction to XML - Khon Kaen Universitykrunapon/courses/188371/slides/intro2xml.pdf · Web Services " XML data is exchanged between service provider & service requester " RSS,

21

Media (Presentation) Independence (1/2)

p Clear separation between contents and presentation

p Contents of data n What the data is

n Is represented by XML document

p Presentation of data n What the data looks like n Can be specified by stylesheet

Page 22: Introduction to XML - Khon Kaen Universitykrunapon/courses/188371/slides/intro2xml.pdf · Web Services " XML data is exchanged between service provider & service requester " RSS,

22

Media (Presentation) Independence (2/2)

p Stylesheet n Instruction of how to present XML data

n CSS p Tailored for HTML browser

n XSL p XML based

p General purpose

p Work with XSLT

Page 23: Introduction to XML - Khon Kaen Universitykrunapon/courses/188371/slides/intro2xml.pdf · Web Services " XML data is exchanged between service provider & service requester " RSS,

23

Separation of Contents from Presentation

p Searching and retrieving data is easy and efficient n Tags give search’able information

p Many applications use the same data in different ways n Employee data can be used by

p Payroll application and Facilities application

p Enables portability of data n Portable over time and space

Page 24: Introduction to XML - Khon Kaen Universitykrunapon/courses/188371/slides/intro2xml.pdf · Web Services " XML data is exchanged between service provider & service requester " RSS,

24

XSLT Transformation p Example (XML -> HTML) XML: <email>[email protected]</email>

XSLT stylesheet can say: p Start a new line p Convert “email” XML tag to “To:” HTML tag p Display “To:” in bold, followed by a space p Display your email address Which produces To:[email protected]

Page 25: Introduction to XML - Khon Kaen Universitykrunapon/courses/188371/slides/intro2xml.pdf · Web Services " XML data is exchanged between service provider & service requester " RSS,

25

Input XML File

Page 26: Introduction to XML - Khon Kaen Universitykrunapon/courses/188371/slides/intro2xml.pdf · Web Services " XML data is exchanged between service provider & service requester " RSS,

26

Output HTML File in Browsers

Page 27: Introduction to XML - Khon Kaen Universitykrunapon/courses/188371/slides/intro2xml.pdf · Web Services " XML data is exchanged between service provider & service requester " RSS,

27

Input XSL File

Page 28: Introduction to XML - Khon Kaen Universitykrunapon/courses/188371/slides/intro2xml.pdf · Web Services " XML data is exchanged between service provider & service requester " RSS,

28

Structure: HTML vs. XML p HTML (Automatic Presentation of

Data) <b> John Doe 1234 </b> // Display in bold

p XML (Automatic Interpretation of Data) <employee> <name>John Doe</name> <employeeID>1234</employeeID>

</employee>

Page 29: Introduction to XML - Khon Kaen Universitykrunapon/courses/188371/slides/intro2xml.pdf · Web Services " XML data is exchanged between service provider & service requester " RSS,

29

XML Structure p Relationship

n Employee is made of Name and EmployeeID

p Hierarchical (Tree-form) n Faster to access n Easier to rearrange n Can be any number of depth

p Enables to build large and complex data p Portability of relationship and

hierarchical structure

Page 30: Introduction to XML - Khon Kaen Universitykrunapon/courses/188371/slides/intro2xml.pdf · Web Services " XML data is exchanged between service provider & service requester " RSS,

30

Desirable Features of XML p  Semantics of data p  Plain Text p  Easily Processed p  Inline usability p  Internationalized p  License-free

Page 31: Introduction to XML - Khon Kaen Universitykrunapon/courses/188371/slides/intro2xml.pdf · Web Services " XML data is exchanged between service provider & service requester " RSS,

31

Semantics of Data p Meaning of data p XML tags “indirectly” specifies the

semantical meaning n Does <name> means “firstname

lastname” or “lastname firstname”?

p Potential for divergence n Industry collaboration to agree upon

the semantical meanings of tags n Need for transformation (XSLT)

Page 32: Introduction to XML - Khon Kaen Universitykrunapon/courses/188371/slides/intro2xml.pdf · Web Services " XML data is exchanged between service provider & service requester " RSS,

32

Plain Text p Can use any text-editing tool

p Easier for humans to read and edit

n Configuration information

n Information description

n Short notices

p Any operating system supports reading and writing text

Page 33: Introduction to XML - Khon Kaen Universitykrunapon/courses/188371/slides/intro2xml.pdf · Web Services " XML data is exchanged between service provider & service requester " RSS,

33

Easily Processed

p Set of Well-formed rules

p Validity checking

p Ready-to-use tools n Parsers and validators

n Transformers

n Browsers

n IDE

Page 34: Introduction to XML - Khon Kaen Universitykrunapon/courses/188371/slides/intro2xml.pdf · Web Services " XML data is exchanged between service provider & service requester " RSS,

34

Inline Usability p Can integrate data from multiple

resources n Can be displayed or processed as a

single document

p Modularization without using Linking

p Example n A book made of independently written

chapters

n Same Copyright text in many books

Page 35: Introduction to XML - Khon Kaen Universitykrunapon/courses/188371/slides/intro2xml.pdf · Web Services " XML data is exchanged between service provider & service requester " RSS,

35

Internationalized p XML is Unicode-based

n You can mix languages

p Both markup and content

p XML tools must support both UTF-8 and UTF-16 encodings

p Critical for world-wide adoption of XML as universal data representation

Page 36: Introduction to XML - Khon Kaen Universitykrunapon/courses/188371/slides/intro2xml.pdf · Web Services " XML data is exchanged between service provider & service requester " RSS,

36

Where Does XML Get Used? p Simple and complex data

representation

p Integration of heterogeneous applications

p Portable data representation

p Displaying and publishing

Page 37: Introduction to XML - Khon Kaen Universitykrunapon/courses/188371/slides/intro2xml.pdf · Web Services " XML data is exchanged between service provider & service requester " RSS,

37

Data Representation p XML encodes the data for a program to

process

p Readable by humans

p Be able to be processed by computers

p Complex relationship can be represented

p Internationalized

p Many 3rd-party tools n Editing, Syntax checking

Page 38: Introduction to XML - Khon Kaen Universitykrunapon/courses/188371/slides/intro2xml.pdf · Web Services " XML data is exchanged between service provider & service requester " RSS,

38

Data Representation Examples p Configuration files

n EJB deployment descriptor

p “make” files (Apache ANT project) p  MSN message history p  File format for electronic office

documents n  OASIS OpenDocument format (ODF) n Microsoft Office Open XML (OOXML)

Page 39: Introduction to XML - Khon Kaen Universitykrunapon/courses/188371/slides/intro2xml.pdf · Web Services " XML data is exchanged between service provider & service requester " RSS,

39

Integration of Heterogeneous Applications

p Typically used with Messaging system

p XML message is minimum contract for communication n Loosely-coupled communication

p Enables easy EAI (Enterprise Application Integration) n Payroll, Finance, Products

p E-commerce n Supplier, distributor, manufacturer, retail

Page 40: Introduction to XML - Khon Kaen Universitykrunapon/courses/188371/slides/intro2xml.pdf · Web Services " XML data is exchanged between service provider & service requester " RSS,

40

Portable Data Representation p Non-proprietary

n Application independent n Object-model independent n Language independent n Platform independent n Communication protocol independent n Communication media independent

p Used for means of “information exchange”

Page 41: Introduction to XML - Khon Kaen Universitykrunapon/courses/188371/slides/intro2xml.pdf · Web Services " XML data is exchanged between service provider & service requester " RSS,

41

Portable Data Representation Examples

p Purchase order, Invoice

p Business transactional semantics

p Patient record

p Mathematical formula

p Musical notation

p Manufacturing process

Page 42: Introduction to XML - Khon Kaen Universitykrunapon/courses/188371/slides/intro2xml.pdf · Web Services " XML data is exchanged between service provider & service requester " RSS,

42

Displaying and Publishing p Common data for different

presentations p Separation of contents from

presentation p Examples

n Web information presented to different client types

n Information rendered to different medium

Page 43: Introduction to XML - Khon Kaen Universitykrunapon/courses/188371/slides/intro2xml.pdf · Web Services " XML data is exchanged between service provider & service requester " RSS,

43

Developer Activities on XML (1/2) p Creating XML document

n Mostly by text-editor or WISWIG tools n Programmatically

p Sending and Receiving XML document n Over any kind of transports

p HTTP, SMTP, FTP, …

n Through programming APIs p Socket APIs

Page 44: Introduction to XML - Khon Kaen Universitykrunapon/courses/188371/slides/intro2xml.pdf · Web Services " XML data is exchanged between service provider & service requester " RSS,

44

Developer Activities on XML (2/2) p Parsing XML document

n Convert XML document into programming objects

p Manipulating programming objects n Application specific way

n Examples p Display

p Save them in database

p Create new XML document

Page 45: Introduction to XML - Khon Kaen Universitykrunapon/courses/188371/slides/intro2xml.pdf · Web Services " XML data is exchanged between service provider & service requester " RSS,

45

XML Standards

p  XML Specification n  XML, Namespaces

p  Validation n  W3C XML Schema

p  Parser n  DOM, SAX , StAX

p Style and Query n  XSL, XSLT, XPath

p Security n  XML Digital Signature, XML Encryption

Page 46: Introduction to XML - Khon Kaen Universitykrunapon/courses/188371/slides/intro2xml.pdf · Web Services " XML data is exchanged between service provider & service requester " RSS,

46

XML Applications p Web Services

n  XML data is exchanged between service provider & service requester

n RSS, ATOM

p  AJAX n  Asynchronous JavaScript and XML

n  AJAX allows Web developers to create interactive Web pages without having to wait for pages to load

Page 47: Introduction to XML - Khon Kaen Universitykrunapon/courses/188371/slides/intro2xml.pdf · Web Services " XML data is exchanged between service provider & service requester " RSS,

47

XML Applications p Web Services

n  XML data is exchanged between service provider & service requester

n RSS, ATOM

p  AJAX n  Asynchronous JavaScript and XML

n  AJAX allows Web developers to create interactive Web pages without having to wait for pages to load

Page 48: Introduction to XML - Khon Kaen Universitykrunapon/courses/188371/slides/intro2xml.pdf · Web Services " XML data is exchanged between service provider & service requester " RSS,

XML in Modern Software p Android

p  Declare UI elements in XML

p  WPF

p  WPF employs XAML, a derivative of XML, to define and link various UI elements

p  Firefox Extension

p  Use XUL (XML User Interface Language, pronounced zool) to define GUIs

Page 49: Introduction to XML - Khon Kaen Universitykrunapon/courses/188371/slides/intro2xml.pdf · Web Services " XML data is exchanged between service provider & service requester " RSS,

49

References (1/2) p XML standards portal http://www.w3.org/xml p XML resources

n  http://www.xml.com n  http://www.oasis-open.org n  http://www.xml.org

p XML Tutorials n  http://www-106.ibm.com/developerworks/views/

xml/tutorials.jsp n  http://www.zvon.org

p Sang Shin XML Course Page http://www.javapassion.com/xml/

Page 50: Introduction to XML - Khon Kaen Universitykrunapon/courses/188371/slides/intro2xml.pdf · Web Services " XML data is exchanged between service provider & service requester " RSS,

References (2/2) p  Wikipedia, “OpenDocument”, http://

en.wikipedia.org/wiki/OpenDocument

p  Wikipedia, “Office Open XML”, http://en.wikipedia.org/wiki/Office_Open_XML

p  Devx.com”, StaX: DOM Ease with SAX Efficiency”, http://www.devx.com/Java/Article/30298

50