Top Banner
Extensible Markup Language Host:Tsai Hsien-pang Teacher: Ke Kai-wei
55

Extensible Markup Language Host:Tsai Hsien-pang Teacher: Ke Kai-wei.

Dec 21, 2015

Download

Documents

Welcome message from author
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
Page 1: Extensible Markup Language Host:Tsai Hsien-pang Teacher: Ke Kai-wei.

Extensible Markup Language

Host:Tsai Hsien-pang

Teacher: Ke Kai-wei

Page 2: Extensible Markup Language Host:Tsai Hsien-pang Teacher: Ke Kai-wei.

The First…

Happy New Year to Everybody.

Page 3: Extensible Markup Language Host:Tsai Hsien-pang Teacher: Ke Kai-wei.

Outline

Introduction The Anatomy of a Document Presentation DTD Syntax Summary

Page 4: Extensible Markup Language Host:Tsai Hsien-pang Teacher: Ke Kai-wei.

Outline

Introduction The Anatomy of a Document Presentation DTD Syntax Summary

Page 5: Extensible Markup Language Host:Tsai Hsien-pang Teacher: Ke Kai-wei.

What’s XML?

XML is a protocol for containing and managing information.

it's can do everything from formatting documents to filtering data.

For information handling that seeks maximum usefulness and flexibility.

Page 6: Extensible Markup Language Host:Tsai Hsien-pang Teacher: Ke Kai-wei.

XML's features

XML can store and organize just about any kind of information in a form that is tailored to your needs.

As an open standard. With Unicode as its standard character set. It’s easy to read and parse by humans and pr

ograms alike. XML is easily combined with stylesheets to cr

eate formatted documents in any style you want.

Page 7: Extensible Markup Language Host:Tsai Hsien-pang Teacher: Ke Kai-wei.

Outline

Introduction The Anatomy of a Document

The Anatomy of a Document Namespaces Well-Formed Documents

Presentation DTD Syntax Summary

Page 8: Extensible Markup Language Host:Tsai Hsien-pang Teacher: Ke Kai-wei.

The Anatomy of a Document

Page 9: Extensible Markup Language Host:Tsai Hsien-pang Teacher: Ke Kai-wei.

A Tree View

Page 10: Extensible Markup Language Host:Tsai Hsien-pang Teacher: Ke Kai-wei.

Ex:<?xml version="1.0" encoding="BIG5"?>< 無線與寬頻網路實驗室 >< 老師 名字 =" 柯老大 ">

< 碩二 >< 頭目 > 鎮年 學長 </ 頭目 >< 頭目 > 文祺 學長 </ 頭目 >

</ 碩二 >< 碩一 >

< 小囉囉 > 蔡憲邦 </ 小囉囉 >< 小囉囉 > 許家豪 </ 小囉囉 >

</ 碩一 ></ 老師 >

Page 11: Extensible Markup Language Host:Tsai Hsien-pang Teacher: Ke Kai-wei.

Ex(2):

Page 12: Extensible Markup Language Host:Tsai Hsien-pang Teacher: Ke Kai-wei.

The XML declaration

There are three properties that you can set:1. Version (ex:”1.0”)

2. Encoding (ex:”big5”)

3. Standalone (ex:”yes”)

Page 13: Extensible Markup Language Host:Tsai Hsien-pang Teacher: Ke Kai-wei.

Elements

Container element syntax

Page 14: Extensible Markup Language Host:Tsai Hsien-pang Teacher: Ke Kai-wei.

Elements(1)

Empty element syntax

Page 15: Extensible Markup Language Host:Tsai Hsien-pang Teacher: Ke Kai-wei.

Elements(2)

Two rules about the positioning of start and end tags: The end tag must come after the start tag. An element's start and end tags must both reside

in the same parent.

Page 16: Extensible Markup Language Host:Tsai Hsien-pang Teacher: Ke Kai-wei.

Ex:<?xml version="1.0" encoding="BIG5"?>< 無線與寬頻網路實驗室 >< 老師 名字 =" 柯老大 ">

< 碩二 >< 頭目 > 鎮年 學長 </ 頭目 >< 頭目 > 文祺 學長 </ 頭目 >

</ 碩二 >< 碩一 >

< 小囉囉 > 蔡憲邦 </ 小囉囉 >< 小囉囉 > 許家豪 </ 小囉囉 >

</ 碩一 ></ 老師 >< 老師 名字 =" 吳老大 ">

Page 17: Extensible Markup Language Host:Tsai Hsien-pang Teacher: Ke Kai-wei.

Ex(2):< 碩二 >

< 頭目 > 慶隆 學長 </ 頭目 ></ 碩二 >< 碩一 >

< 小囉囉 > 林澤賢 </ 小囉囉 >< 小囉囉 > 簡睿毅 </ 小囉囉 >

</ 碩一 ></ 老師 ></ 無線與寬頻網路實驗室 >

Page 18: Extensible Markup Language Host:Tsai Hsien-pang Teacher: Ke Kai-wei.

Well-Formed Documents An element containing text or elements must have start a

nd end tags.

An empty element's tag must have a slash (/) before the end bracket.

Page 19: Extensible Markup Language Host:Tsai Hsien-pang Teacher: Ke Kai-wei.

All attribute values must be in quotes.

Elements may not overlap.

Isolated markup characters may not appear in parsed content.

Well-Formed Documents(1)

Page 20: Extensible Markup Language Host:Tsai Hsien-pang Teacher: Ke Kai-wei.

Element names may start only with letters and underscores, and may contain onlyletters, numbers, hyphens, periods, and underscores. Colons are allowed for namespaces.

Well-Formed Documents(2)

Page 21: Extensible Markup Language Host:Tsai Hsien-pang Teacher: Ke Kai-wei.

XML Is Not HTML

Element names are case-sensitive in XML. HTML allows you to write tags in whatever case you want.

In XML, container elements always require both a start and an end tag. In HTML, you can drop the end tag in some cases.

Empty XML elements require a slash before the right bracket (i.e., <example/>), whereas HTML uses alone start tag with no final slash.

XML elements treat whitespace as part of the content, preserving it unless they are explicitly told not to. But in HTML, most elements throw away extra spaces and line breaks when formatting content in the browser.

Page 22: Extensible Markup Language Host:Tsai Hsien-pang Teacher: Ke Kai-wei.

Namespaces:

Namespace is a group of element and attribute names.

Declare that an element exists within a particular namespace and that it should be validated against that namespace's DTD.

Two XML objects in different name-spaces can have the same name. Each element or attribute specify which namespace it

comes from by including the namespace as a prefix.

Page 23: Extensible Markup Language Host:Tsai Hsien-pang Teacher: Ke Kai-wei.

Example:

Page 24: Extensible Markup Language Host:Tsai Hsien-pang Teacher: Ke Kai-wei.

Example:

Page 25: Extensible Markup Language Host:Tsai Hsien-pang Teacher: Ke Kai-wei.

Namespace declaration syntax

1. Alert the XML parser that this attribute is a namespace declaration.

2. A namespace prefix.

3. An equals sign,and finally a URL in quotes

Page 26: Extensible Markup Language Host:Tsai Hsien-pang Teacher: Ke Kai-wei.

Example:

Page 27: Extensible Markup Language Host:Tsai Hsien-pang Teacher: Ke Kai-wei.

Qualified name syntax:

1. A namespace prefix.

2. Colon.

3. The local name of the element or attribute.

Page 28: Extensible Markup Language Host:Tsai Hsien-pang Teacher: Ke Kai-wei.

Ex:<?xml version="1.0"?>

<myns:journal xmlns:myns="http://www.psycholabs.org/mynamespace/"><myns:experiment><myns:date>March 4, 2001</myns:date>

<myns:subject>Effects of Caffeine on Psychokinetic Ability</myns:subject><myns:abstract>The experiment consists of a subject, a can of

caffeinated soda, and a goldfish tank. The ability to make agoldfish turn in a circle through the power of a human's mentalcontrol is given by the well-known equation:

<eq:formula xmlns:eq="http://www.mathstuff.org/"><eq:variable>P</eq:variable> =<eq:variable>m</eq:variable><eq:variable>M</eq:variable> /<eq:variable>d</eq:variable>

</eq:formula>

where P is the probability it will turn in a given time interval,m is the mental acuity of the fish, M is the mental acuity ofthe subject, and d is the distance between fish and subject.</myns:abstract>

...</myns:experiment>

</myns:journal>

Page 29: Extensible Markup Language Host:Tsai Hsien-pang Teacher: Ke Kai-wei.

Ex(1):<?xml version="1.0"?>

<myns:journal xmlns:myns="http://www.psycholabs.org/mynamespace/"><myns:experiment><myns:date>March 4, 2001</myns:date>

<myns:subject>Effects of Caffeine on Psychokinetic Ability</myns:subject><myns:abstract>The experiment consists of a subject, a can of

caffeinated soda, and a goldfish tank. The ability to make agoldfish turn in a circle through the power of a human's mentalcontrol is given by the well-known equation:

<eq:formula xmlns:eq="http://www.mathstuff.org/"><eq:variable>P</eq:variable> =<eq:variable>m</eq:variable><eq:variable>M</eq:variable> /<eq:variable>d</eq:variable>

</eq:formula>

where P is the probability it will turn in a given time interval,m is the mental acuity of the fish, M is the mental acuity ofthe subject, and d is the distance between fish and subject.</myns:abstract>

...</myns:experiment>

</myns:journal>

Page 30: Extensible Markup Language Host:Tsai Hsien-pang Teacher: Ke Kai-wei.

Ex(2):<?xml version="1.0"?><myns:journal xmlns:myns="http://www.psycholabs.org/mynamespace/">

<myns:experiment><myns:date>March 4, 2001</myns:date>

<myns:subject>Effects of Caffeine on Psychokinetic Ability</myns:subject><myns:abstract>The experiment consists of a subject, a can of

caffeinated soda, and a goldfish tank. The ability to make agoldfish turn in a circle through the power of a human's mentalcontrol is given by the well-known equation:

<eq:formula xmlns:eq="http://www.mathstuff.org/"><eq:variable>P</eq:variable> =<eq:variable>m</eq:variable><eq:variable>M</eq:variable> /<eq:variable>d</eq:variable>

</eq:formula>

where P is the probability it will turn in a given time interval,m is the mental acuity of the fish, M is the mental acuity ofthe subject, and d is the distance between fish and subject.</myns:abstract>

...</myns:experiment>

</myns:journal>

Page 31: Extensible Markup Language Host:Tsai Hsien-pang Teacher: Ke Kai-wei.

Outline

Introduction The Anatomy of a Document Presentation DTD Syntax Summary

Page 32: Extensible Markup Language Host:Tsai Hsien-pang Teacher: Ke Kai-wei.

Presentation:Stylesheet

Keeping style information out of the markup frees the author.

Keeping style settings in a separate document makes the designer's job easier.

Your options for presenting the document increase.

Stylesheets can be combined, with pieces substituted for particular needs

Page 33: Extensible Markup Language Host:Tsai Hsien-pang Teacher: Ke Kai-wei.
Page 34: Extensible Markup Language Host:Tsai Hsien-pang Teacher: Ke Kai-wei.

•A stylesheet helps produce a formatted document

Page 35: Extensible Markup Language Host:Tsai Hsien-pang Teacher: Ke Kai-wei.

•One stylesheet can be used by many XML documents

Page 36: Extensible Markup Language Host:Tsai Hsien-pang Teacher: Ke Kai-wei.

•Mix and match stylesheets for different purposes

Page 37: Extensible Markup Language Host:Tsai Hsien-pang Teacher: Ke Kai-wei.

•A cascade of stylesheets

Page 38: Extensible Markup Language Host:Tsai Hsien-pang Teacher: Ke Kai-wei.

Cascading Style Sheets (CSS)

Simple to use, easy to learn, and quite powerful, although a bit underimplemented by browser vendors.

Early player in the stylesheet story. Combine many stylesheets into one, cascadi

ng.

Page 39: Extensible Markup Language Host:Tsai Hsien-pang Teacher: Ke Kai-wei.

XSL-FO

eXtensible Stylesheet Language for Formatting Objects (XSL-FO).

A language for formatting XML documents. Destined to become the preferred stylesheet l

anguage for complex formatting, as it is much more detailed than CSS.

More closely tied to XML's nested-container structure.

Page 40: Extensible Markup Language Host:Tsai Hsien-pang Teacher: Ke Kai-wei.

Outline

Introduction The Anatomy of a Document Presentation DTD Syntax Summary

Page 41: Extensible Markup Language Host:Tsai Hsien-pang Teacher: Ke Kai-wei.

Document Models:

The process of formally defining a language in XML is called document modeling.

It defines the documents that can be produced with a language.

Document Type Definitions (DTDs) XML Schema

Page 42: Extensible Markup Language Host:Tsai Hsien-pang Teacher: Ke Kai-wei.

DTD Syntax

It declares a set of allowed elements. It defines a content model for each element. It declares a set of allowed attributes for each

element. It provides a variety of mechanisms to make

managing the model easier.

Page 43: Extensible Markup Language Host:Tsai Hsien-pang Teacher: Ke Kai-wei.

Declarations

Page 44: Extensible Markup Language Host:Tsai Hsien-pang Teacher: Ke Kai-wei.

The document type declaration

1. The declaration starts with the literal string.2. The first XML element to appear in the document and the

one that contains the rest of the document.3. Include the URI of the DTD.4. Bound on either side by square brackets.

Page 45: Extensible Markup Language Host:Tsai Hsien-pang Teacher: Ke Kai-wei.

Element Declarations

Element declarations alert. name content model

Page 46: Extensible Markup Language Host:Tsai Hsien-pang Teacher: Ke Kai-wei.

Five content models:

Empty elements Ex : <!ELEMENT graphic EMPTY>

Elements with no content restrictions Ex : <!ELEMENT contain-anything ALL>

Elements containing only character data Ex : <!ELEMENT emphasis (#PCDATA)>

Elements containing only elements Elements with mixed content

Ex : <!ELEMENT para (#PCDATA | emphasis | xref)*>

Page 47: Extensible Markup Language Host:Tsai Hsien-pang Teacher: Ke Kai-wei.

Ex:<?xml version="1.0"?>

<!DOCUMENT record [<!ELEMENT doc (title, listing+)><!ELEMENT title (#PCDATA)*><!ELEMENT listing (#PCDATA)*><!ATTLIST listingformat NOTATION (scheme-lisp | ansi-c) #REQUIRED><!NOTATION scheme-lisp SYSTEM "IEEE 1178-1990"><!NOTATION ansi-c SYSTEM "ISO/IEC 9899:1999">]><doc><title>Factorial Function</title><listing format="scheme-lisp">(defun fact (lambda (n) (if (= n 1) 1 (fact (- n 1)))))</listing><listing format="ansi-c">int fact( int n ) {if( n == 1 ) return 1;return n * fact( n - 1 );}</listing></doc>

Page 48: Extensible Markup Language Host:Tsai Hsien-pang Teacher: Ke Kai-wei.

Ex(1):<?xml version="1.0" encoding="BIG5"?><!DOCTYPE 無線與寬頻網路實驗室 [

<!ELEMENT 無線與寬頻網路實驗室 ( 老師 +)><!ELEMENT 老師 ( 碩二 , 碩一 )><!ATTLIST 老師名字 NOTATION ( 柯老大 | 吳老大 ) #REQUIRED><!NOTATION 柯老大 SYSTEM "k"><!NOTATION 吳老大 SYSTEM "w">

<!ELEMENT 碩二 ( 頭目 *)><!ELEMENT 頭目 (#PCDATA)>

<!ELEMENT 碩一 ( 小囉囉 *)><!ELEMENT 小囉囉 (#PCDATA)>

]>

Page 49: Extensible Markup Language Host:Tsai Hsien-pang Teacher: Ke Kai-wei.

Symbols Used in Element

Page 50: Extensible Markup Language Host:Tsai Hsien-pang Teacher: Ke Kai-wei.

Attribute List Declarations

Page 51: Extensible Markup Language Host:Tsai Hsien-pang Teacher: Ke Kai-wei.

Ex:

<!ATTLIST memo

id ID #REQUIRED (1)

security (high | low) "high" (2)

>

1) The #REQUIRED keyword means that this attribute must be specified by the author.

2) The second attribute, can take either of two values, high or low; the default is high.

Page 52: Extensible Markup Language Host:Tsai Hsien-pang Teacher: Ke Kai-wei.

Ex:<?xml version="1.0"?><!DOCUMENT record [<!ELEMENT doc (title, listing+)><!ELEMENT title (#PCDATA)*><!ELEMENT listing (#PCDATA)*><!ATTLIST listingformat NOTATION (scheme-lisp | ansi-c) #REQUIRED><!NOTATION scheme-lisp SYSTEM "IEEE 1178-1990"><!NOTATION ansi-c SYSTEM "ISO/IEC 9899:1999">]><doc><title>Factorial Function</title><listing format="scheme-lisp">(defun fact (lambda (n) (if (= n 1) 1 (fact (- n 1)))))</listing><listing format="ansi-c">int fact( int n ) {if( n == 1 ) return 1;return n * fact( n - 1 );}</listing></doc>

Page 53: Extensible Markup Language Host:Tsai Hsien-pang Teacher: Ke Kai-wei.

Outline

Introduction The Anatomy of a Document Presentation DTD Syntax Summary

Page 54: Extensible Markup Language Host:Tsai Hsien-pang Teacher: Ke Kai-wei.

XML’s Benefit

Simplicity Openness Extensibility Self-description Contains machine-readable context

information Separates content from presentation

Page 55: Extensible Markup Language Host:Tsai Hsien-pang Teacher: Ke Kai-wei.

Summary

Introduction The Anatomy of a Document Presentation DTD Syntax