Title: XML
1XML
2What is XML?
XML eXstensible Markup Language a meta
language for defining markup languages.
Examples MathML, SVG (Scalable Vector
Graphics), WML (Wireless Markup Language), XBRL
(Extensible Business Reporting Language), XUL
(Extensible User Interface Language), PDML
(Product Data Markul Language), CML (Chemical
ML), VoiceXML, VML (Vector ML), cXML (Commerce
XML), tpaML (Traqding partner agreement XML),
SMBXML (Small to Medium Business XML), FinXML
(Financial XML), SOAP, XHTML, OWL
3XML History
- Standard Generalized Markup Language
- Invented in 1980s for publishing industry
- Markup meta language
- HTML is an SGML language
- Ancestor of XML
4Uses of XML
- Data Storage
- Object Serialization
- Presentation Independent
- Language Independent
- Application Initialization
- Message Passing
- Between Tiers
- Data-Business-Presentation-Client
- SOAP and Web Services
5An XML Document Contains
- A Prolog
- Elements
- lttaggt content lt/taggt
- Comments
- lt!-- don't read this --gt
- CDATA Sections
- lt!CDATA pre-formatted textgt
- Processing Instructions (PIs)
- lt? do it ?gt
6Format of an XML Document
lt?xml version"1.0"?gtltrootgt ELEMENT
ELEMENT ...lt/rootgt
7Tree Structure of an XML Document
8A Document Prolog Contains
- XML Declaration
- lt?xml version"1.0" ?gt
- DTD (optional)
- Style Sheet (optional)
- etc.
lt?xml version"1.0"?gtlt!DOCTYPE addresses SYSTEM
"addresses.dtd"gtlt?xml-stylesheet type"text/xsl"
href"addresses1.xsl"?gt
9An XML Element Contains
- ltTAG attributesgt content lt/TAGgt
- ltDATE status"cancelled"gt
09/01/2002lt/DATEgt - An empty element
- ltTAG attributes /gt
10Example book.xml
lt?xml version"1.0"?gtltaddressesgt PERSON
PERSON PERSON ...lt/addressesgt
11A Person Element (1)
ltpersongt NAME ADDRESS PHONElt/persongt
12A Person Element (2)
ltpersongt ltnamegt ltfirstgt Joe lt/firstgt
ltlastgt Smith lt/lastgt lt/namegt ltaddressgt
ltstreetgt 123 Sesame St lt/streetgt
ltcitygt New York lt/citygt ltstategt NY
lt/stategt lt/addressgt ltphonegt (555) 555-1234
lt/phonegt lt/persongt
13Displaying XML in IE
14Grammars
- G a grammar
- L(G) Language defined by G
- w ?L(G) means w is a valid L(G) sentence
- Example
- G English grammar
- G Java grammar
15Grammar Rules
- An EBNF grammar is a list of rules of the form
- PARENT CHILDREN
- CHILDREN is a regular expression
- A B, A B, A, A?, 'leaf'
16Addresses EBNF
ADDRESSES PERSONPERSON NAME ADDRESS
PHONENAME FIRST LASTADDRESS STREET CITY
STATEPHONE, FIRST, LAST, STREET, CITY, STATE
STRING
17addresses.dtd
lt!ELEMENT addresses (person)gtlt!ELEMENT person
(name, address, phone)gtlt!ELEMENT name
(first, last)gtlt!ELEMENT first
(PCDATA)gtlt!ELEMENT last
(PCDATA)gtlt!ELEMENT address (street, city,
state)gtlt!ELEMENT street (PCDATA)gtlt!ELEMEN
T city (PCDATA)gtlt!ELEMENT state
(PCDATA)gtlt!ELEMENT phone (PCDATA)gt
18book.xml (with a dtd)
lt?xml version"1.0"?gtlt!DOCTYPE addresses SYSTEM
"addresses.dtd"gtltaddressesgt PERSON PERSON
PERSON ...lt/addressesgt
19Well Formed vs. Valid Documents
- Validating Parsers determine if an XML document
conforms to its DTD - Non-validating parsers merely determine if an xml
document is well formed
20Extensible Style Sheet Language
- XSL is an XML language for describing a
transformation - An XSL document describes a transformation that
transforms XML documents into xHTML documents
21XSL Format
ltxslstylesheet version"1.0"
xmlnsxsl"http//www.w3.org/TR/WD-xsl"gtltxsltemp
late match"/"gt HTML XML instructions lt/xslt
emplategtlt/xslstylesheetgt
22XSL Markup
- ltxslfor-each selectTAGgt ... lt/for-eachgt
- selects each element in an XML document matching
TAG and performs ... - ltxslvalue-of selectTAG /gt
- Displays the value of TAG
23addresses.xsl
lthtmlgtltheadgtlttitlegt Addresses lt/titlegtlt/headgtltbody
gtHere are your addressesltxslfor-each
select"addresses/person"gt ltbr /gtlthr /gt ltfont
color"red"gt ltbgtltigt name ltxslvalue-of
select"name"/gt lt/igtlt/bgt lt/fontgt ltbr /gt
phone ltxslvalue-of select"phone"/gtlt/xslfor-e
achgt ltbr /gtlthr /gtlt/bodygtlt/htmlgtlt/xsltemplategt
lt/xslstylesheetgt
24book.xml (with an xsl)
lt?xml version"1.0"?gtlt!DOCTYPE addresses SYSTEM
"addresses.dtd"gtlt?xml-stylesheet type"text/xsl"
href"addresses.xsl"?gtltaddressesgt PERSON
PERSON PERSON ...lt/addressesgt
25Displaying book.xml in IE (2)