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

Post on 21-Dec-2015

217 Views

Category:

Documents

3 Downloads

Preview:

Click to see full reader

Transcript

Extensible Markup Language

Host:Tsai Hsien-pang

Teacher: Ke Kai-wei

The First…

Happy New Year to Everybody.

Outline

Introduction The Anatomy of a Document Presentation DTD Syntax Summary

Outline

Introduction The Anatomy of a Document Presentation DTD Syntax Summary

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.

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.

Outline

Introduction The Anatomy of a Document

The Anatomy of a Document Namespaces Well-Formed Documents

Presentation DTD Syntax Summary

The Anatomy of a Document

A Tree View

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

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

</ 碩二 >< 碩一 >

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

</ 碩一 ></ 老師 >

Ex(2):

The XML declaration

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

2. Encoding (ex:”big5”)

3. Standalone (ex:”yes”)

Elements

Container element syntax

Elements(1)

Empty element syntax

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.

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

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

</ 碩二 >< 碩一 >

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

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

Ex(2):< 碩二 >

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

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

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

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.

All attribute values must be in quotes.

Elements may not overlap.

Isolated markup characters may not appear in parsed content.

Well-Formed Documents(1)

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)

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.

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.

Example:

Example:

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

Example:

Qualified name syntax:

1. A namespace prefix.

2. Colon.

3. The local name of the element or attribute.

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>

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>

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>

Outline

Introduction The Anatomy of a Document Presentation DTD Syntax Summary

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

•A stylesheet helps produce a formatted document

•One stylesheet can be used by many XML documents

•Mix and match stylesheets for different purposes

•A cascade of stylesheets

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.

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.

Outline

Introduction The Anatomy of a Document Presentation DTD Syntax Summary

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

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.

Declarations

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.

Element Declarations

Element declarations alert. name content model

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)*>

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>

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)>

]>

Symbols Used in Element

Attribute List Declarations

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.

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>

Outline

Introduction The Anatomy of a Document Presentation DTD Syntax Summary

XML’s Benefit

Simplicity Openness Extensibility Self-description Contains machine-readable context

information Separates content from presentation

Summary

Introduction The Anatomy of a Document Presentation DTD Syntax

top related