Objectives Objectives � What is XML , in particular in relation to HTML An Introduction to XML and Web Technologies An Introduction to XML and Web Technologies � The XML data model and its textual representation XML Documents XML Documents � The XML Namespace mechanism Anders Møller & Michael I. Schwartzbach 2006 Addison-Wesley An Introduction to XML and Web Technologies 2 What is XML? Recipes in XML What is XML? Recipes in XML � XML: E x tensible M arkup L anguage � Define our own “ Recipe Markup Language ” � A framework for defining markup languages � Choose markup tags that correspond to concepts in this application domain � Each language is targeted at its own • recipe , ingredient , amount , ... application domain with its own markup tags � No canonical choices � There is a common set of generic tools for • granularity of markup? processing XML documents • structuring? � XHTML : an XML variant of HTML • elements or attributes? � Inherently internationalized and platform • ... independent (Unicode) � Developed by W3C, standardized in 1998 An Introduction to XML and Web Technologies 3 An Introduction to XML and Web Technologies 4 1
Example (1/2) Example (2/2) Example (1/2) Example (2/2) <col l ect i on> <com m ent > <descr i pt i on>Reci pes suggest ed by Jane Dow</ descr i pt i on> Rhubar b Cobbl er m ade wi t h bananas as t he m ai n sweet ener . I t was del i ci ous. <r eci pe i d=" r 117" > </ com m ent > <t i t l e>Rhubar b Cobbl er </ t i t l e> <dat e>W ed, 14 Jun 95</ dat e> <nut r i t i on cal or i es=" 170" f at =" 28% " car bohydr at es=" 58% " pr ot ei n=" 14% " / > <i ngr edi ent nam e=" di ced r hubar b" am ount =" 2. 5" uni t =" cup" / > <r el at ed r ef =" 42" >G ar den Q ui che i s al so yum m y</ r el at ed> <i ngr edi ent nam e=" sugar " am ount =" 2" uni t =" t abl espoon" / > </ r eci pe> <i ngr edi ent nam e=" f ai r l y r i pe banana" am ount =" 2" / > </ col l ect i on> <i ngr edi ent nam e=" ci nnam on" am ount =" 0. 25" uni t =" t easpoon" / > <i ngr edi ent nam e=" nut m eg" am ount =" 1" uni t =" dash" / > <pr epar at i on> <st ep> Com bi ne al l and use as cobbl er , pi e, or cr i sp. </ st ep> </ pr epar at i on> An Introduction to XML and Web Technologies 5 An Introduction to XML and Web Technologies 6 Building on the XML Notation XML Trees Building on the XML Notation XML Trees � Defining the syntax of our recipe language � Conceptually, an XML document is a tree structure • DTD, XML Schema, ... � Showing recipe documents in browsers • node, edge • root, leaf • XPath, XSLT • child, parent � Recipe collections as databases • sibling (ordered), • XQuery ancestor, � Building a Web-based recipe editor descendant • HTTP, Servlets, JSP, ... � ... – the topics of the following weeks... An Introduction to XML and Web Technologies 7 An Introduction to XML and Web Technologies 8 2
An Analogy: File Systems Tree View of the XML Recipes An Analogy: File Systems Tree View of the XML Recipes An Introduction to XML and Web Technologies 9 An Introduction to XML and Web Technologies 10 Nodes in XML Trees Textual Representation Nodes in XML Trees Textual Representation � Text nodes : carry the actual contents, leaf nodes � Text nodes : written as the text they carry � Element nodes : define hierarchical logical � Element nodes : start-end tags groupings of contents, each have a name • < bla ... > ... </ bla > � Attribute nodes : unordered, each associated • short-hand notation for empty elements: < bla / > with an element node, has a name and a value � Attribute nodes : name =“ value ” in start tags � Comment nodes : ignorable meta-information � Comment nodes : <! - - bla - - > � Processing instructions : instructions to specific � Processing instructions : <? target value ?> processors, each have a target and a value � Root nodes : implicit � Root nodes : every XML tree has one root node that represents the entire tree An Introduction to XML and Web Technologies 11 An Introduction to XML and Web Technologies 12 3
Browsing XML (without XSLT) More Constructs Browsing XML (without XSLT) More Constructs � XML declaration � Character references � CDATA sections � Document type declarations and entity references explained later... � Whitespace? An Introduction to XML and Web Technologies 13 An Introduction to XML and Web Technologies 14 Example Well- -formedness formedness Example Well � Every XML document must be well-formed <?xm l ver si on=" 1. 1" encodi ng=" I SO - 8859- 1" ?> <! DO CTYPE f eat ur es SYSTEM " exam pl e. dt d" > • start and end tags must match and nest properly <f eat ur es a=" b" > � • <x><y></y></x> <?m yt ool her e i s som e i nf or m at i on speci f i c t o m yt ool ?> • </z><x><y></x></y> El señor est á bi en, gar çon! Copyr i ght © 2005 • exactly one root element <! [ CDATA[ <t hi s i s not a t ag> ] ] > • ... <! - - al ways r em em ber t o speci f y t he � in other words, it defines a proper tree structure r i ght char act er encodi ng - - > </ f eat ur es> � XML parser : given the textual XML document, constructs its tree representation An Introduction to XML and Web Technologies 15 An Introduction to XML and Web Technologies 16 4
Simpler Alternatives? Applications Simpler Alternatives? Applications S-expressions, 1958: Rough classification: � Data-oriented languages ( col l ect i on � Document-oriented languages ( r eci pe � Protocols and programming languages ( t i t l e " Rhubar b Cobbl er " ) ( dat e " W ed, 14 Jun 95" ) . . . � Hybrids ) ) � XML is defined as a simplified subset of SGML � XML could have been designed simpler... � ... but it wasn’t [end of discussion] An Introduction to XML and Web Technologies 17 An Introduction to XML and Web Technologies 18 Example: XHTML Example: CML Example: XHTML Example: CML <m ol ecul e i d=" M ETHANO L" > <?xm l ver si on=" 1. 0" encodi ng=" UTF- 8" ?> <at om Ar r ay> <st r i ngAr r ay bui l t i n=" i d" >a1 a2 a3 a4 a5 a6</ st r i ngAr r ay> <ht m l xm l ns=" ht t p: / / www. w3. or g/ 1999/ xht m l " > <st r i ngAr r ay bui l t i n=" el em ent Type" >C O H H H H</ st r i ngAr r ay> <head><t i t l e>Hel l o wor l d! </ t i t l e></ head> <f l oat Ar r ay bui l t i n=" x3" uni t s=" pm " > - 0. 748 0. 558 . . . <body> </ f l oat Ar r ay> <h1>Thi s i s a headi ng</ h1> <f l oat Ar r ay bui l t i n=" y3" uni t s=" pm " > - 0. 015 0. 420 . . . Thi s i s som e t ext . </ f l oat Ar r ay> </ body> <f l oat Ar r ay bui l t i n=" z3" uni t s=" pm " > </ ht m l > 0. 024 - 0. 278 . . . </ f l oat Ar r ay> </ at om Ar r ay> </ m ol ecul e> An Introduction to XML and Web Technologies 19 An Introduction to XML and Web Technologies 20 5
Recommend
More recommend