xml extensible markup language. what is xml? ● meta-markup language ● a language for defining a...

28
XML Extensible Markup Language

Upload: thomas-bruce

Post on 29-Dec-2015

235 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: XML Extensible Markup Language. What is XML? ● meta-markup language ● a language for defining a family of languages ● semantic/structured mark-up language

XML

Extensible Markup Language

Page 2: XML Extensible Markup Language. What is XML? ● meta-markup language ● a language for defining a family of languages ● semantic/structured mark-up language

What is XML?

● meta-markup language● a language for defining a family of languages● semantic/structured mark-up language

– defines structure and meaning, NOT formatting or presentation

Page 3: XML Extensible Markup Language. What is XML? ● meta-markup language ● a language for defining a family of languages ● semantic/structured mark-up language

Why XML?

● supports construction of domain specific markup languages

● creates a common data format● facilitates data interchange● structures large, complex documents

Page 4: XML Extensible Markup Language. What is XML? ● meta-markup language ● a language for defining a family of languages ● semantic/structured mark-up language

History

● Standard Generalized Markup Language (SGML)– too complex

● Hyper-Text Markup Language (HTML)– not extensible, limited to small set of fixed tags– polluted with non-semantic tags (e.g. <center>, <i>,

and the dreaded <blink>● XML working group formed in 1996● XML is really a slimmed down SGML

Page 5: XML Extensible Markup Language. What is XML? ● meta-markup language ● a language for defining a family of languages ● semantic/structured mark-up language

XML Applications

● Chemical Markup Language (CML)– originaly a SGML application– used to describe: molecular structures and sequences,

spectrographic analysis, crystallography, chemical databases, and so on

● Mathematical Markup Language (MathML)– adequate for almost all: education, scientific,

engineering, business, economics, and statistics needs– limited for advances math/theoretical physics

Page 6: XML Extensible Markup Language. What is XML? ● meta-markup language ● a language for defining a family of languages ● semantic/structured mark-up language

MathML example

<apply><power/><apply>

<plus/><ci>a</ci><ci>b</ci>

</apply><cn>2</cn>

</apply>

(a+b)2

Page 7: XML Extensible Markup Language. What is XML? ● meta-markup language ● a language for defining a family of languages ● semantic/structured mark-up language

XML Document “Goodness”

● well-formed– satisfies the basic rules of XML syntax

● valid– satisifes the domain specific rules for the language as

definded in the Document Type Definintion (DTD)

Page 8: XML Extensible Markup Language. What is XML? ● meta-markup language ● a language for defining a family of languages ● semantic/structured mark-up language

Well-formed

1.Must start with an XML declaratoin

2.Elements with content must contain matching start and end tags

3.Empty elements must end with />

4.The document must contain exactly one element that contains all other elements

5.Elements may nest but not overlap

Page 9: XML Extensible Markup Language. What is XML? ● meta-markup language ● a language for defining a family of languages ● semantic/structured mark-up language

XML Declaration

<?xml version=”1.0” standalone=”yes” ?>– standalone – yes if this file contains a complete

document

Page 10: XML Extensible Markup Language. What is XML? ● meta-markup language ● a language for defining a family of languages ● semantic/structured mark-up language

Tags

● anything that begins with < and ends with >● end tags begin with </● empty tags end with />● tag names

– start with letter or underscore (_)– remianing characters can be letters, numbers, _,

hyphens or periods

Page 11: XML Extensible Markup Language. What is XML? ● meta-markup language ● a language for defining a family of languages ● semantic/structured mark-up language

Attributes

● start tags can include zero or more attributes● attributes are name/value pairs separated by and

equals sign (=)● the rules for attribute names are the same as for

tag names● the value is any string enclosed in quotes (single

or double)● if the sting contains quotes entity references must

be used: &apos; or &quot;

Page 12: XML Extensible Markup Language. What is XML? ● meta-markup language ● a language for defining a family of languages ● semantic/structured mark-up language

Comments

<!-- important message -->● can't be nested or contained inside start/end tags

Page 13: XML Extensible Markup Language. What is XML? ● meta-markup language ● a language for defining a family of languages ● semantic/structured mark-up language

Entity References

&amp; &

&lt; <

&gt; >

&quot; “

&apos; '

Page 14: XML Extensible Markup Language. What is XML? ● meta-markup language ● a language for defining a family of languages ● semantic/structured mark-up language

CDATA

● used for content that resembles XML:

<![CDATA[

<?xml version=”1.0” standalone=”yes” ?>

<greeting>

Hello!

</greeting>

]]>

Page 15: XML Extensible Markup Language. What is XML? ● meta-markup language ● a language for defining a family of languages ● semantic/structured mark-up language

Valid Documents

● body matches Document Type Definition (DTD)

Page 16: XML Extensible Markup Language. What is XML? ● meta-markup language ● a language for defining a family of languages ● semantic/structured mark-up language

DTDs

<?xml version=”1.0” standalone=”yes” ?>

<!DOCTYPE greeting [

<!ELEMENT greeting (#PCDATA)>

]>

<greeting>

Hello!

</greeting>

Page 17: XML Extensible Markup Language. What is XML? ● meta-markup language ● a language for defining a family of languages ● semantic/structured mark-up language

ELEMENTs

● name follwowed pattern● pattern is similar to a regular expression

Page 18: XML Extensible Markup Language. What is XML? ● meta-markup language ● a language for defining a family of languages ● semantic/structured mark-up language

ATTLIST

● specifies attributes for a tag

<!ATTLIST greeting language CDATA “english”>

Page 19: XML Extensible Markup Language. What is XML? ● meta-markup language ● a language for defining a family of languages ● semantic/structured mark-up language

Internal Document Type

<!DOCTYPE root_element_name [declarations

]>

<!DOCTYPE greeting [<!ELEMENT greeting (#PCDATA)>

]>

Page 20: XML Extensible Markup Language. What is XML? ● meta-markup language ● a language for defining a family of languages ● semantic/structured mark-up language

External Document Type (System)

<!DOCTYPE root_element_name SYSTEM DTD_URL>

<!DOCTYPE greetingSYSTEM “http://abc.com/greet.dtd” >

Page 21: XML Extensible Markup Language. What is XML? ● meta-markup language ● a language for defining a family of languages ● semantic/structured mark-up language

External Document Type (Public)

<!DOCTYPE root_element_name PUBLIC DTD_name DTD_URL>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/ xhtml1/DTD/xhtml1-strict.dtd">

Page 22: XML Extensible Markup Language. What is XML? ● meta-markup language ● a language for defining a family of languages ● semantic/structured mark-up language

Internal General Entity

<!ENTITY name “replacement text”>

<!ENTITY bk “Brian K. Koehler”><!ENTITY bkc “Copyright 2002, &bk;”>...THE END &bkc;

Page 23: XML Extensible Markup Language. What is XML? ● meta-markup language ● a language for defining a family of languages ● semantic/structured mark-up language

Internal Parameter Entity

<!ENTITY % name “replacement text”>

<!ENTITY event “(place?, date?)”>...<!ELEMENT ticket (vehicle,%event;)>

Page 24: XML Extensible Markup Language. What is XML? ● meta-markup language ● a language for defining a family of languages ● semantic/structured mark-up language

ELEMENTs

<!ELEMENT name content_type>

<!ELEMENT document ANY><!ELEMENT street (#PCDATA)><!ELEMENT accident (place,date)><!ELEMENT head (title,meta*)>

Page 25: XML Extensible Markup Language. What is XML? ● meta-markup language ● a language for defining a family of languages ● semantic/structured mark-up language

ELEMENT content_type

● ANY – anything● #PCDATA – only character data – no contained

elements● EMPTY – element contains no content● reg_exp – a regular expression denoting

acceptable children

Page 26: XML Extensible Markup Language. What is XML? ● meta-markup language ● a language for defining a family of languages ● semantic/structured mark-up language

Regular expressions

● element_name● re+ 1 or more● re* 0 or more● re? 0 or 1● (re1 | re2 | ... | reN ) re1 or re2 ... or reN● (re1, re2, ..., reN ) re1 followed by re2, ... reN

Page 27: XML Extensible Markup Language. What is XML? ● meta-markup language ● a language for defining a family of languages ● semantic/structured mark-up language

XHTML head element

● what is the declaration for the XHTML “head” element:– must contain exactly one “title” element– may contain at most one “base” element– may contain 0 or more “meta” elements– title, base, and meta elements can appear in any order

Page 28: XML Extensible Markup Language. What is XML? ● meta-markup language ● a language for defining a family of languages ● semantic/structured mark-up language

ATTLISTs

<!ATTLIST element_nameattribute_nametype“default value”>

<!ATTLIST img alt CDATA #REQUIRED><!ATTLIST table border CDATA “1”>