1 XML eXtensible Markup Language
2 XML vs. HTML HTML is a HyperText Markup language HTML is a HyperText Markup language Designed for a specific application, namely, presenting and linking hypertext documents Designed for a specific application, namely, presenting and linking hypertext documents XML describes structure and content (“semantics”) XML describes structure and content (“semantics”) The presentation is defined separately from the structure and the content The presentation is defined separately from the structure and the content
3 An Address Book as an XML document Donald Duck Miki Mouse
4 Main Features of XML No fixed set of tags No fixed set of tags New tags can be added for new applications New tags can be added for new applications An agreed upon set of tags can be used in many applications An agreed upon set of tags can be used in many applications Namespaces facilitate uniform and coherent descriptions of data Namespaces facilitate uniform and coherent descriptions of data For example, a namespace for address books determines whether to use or For example, a namespace for address books determines whether to use or
5 Main Features of XML (cont’d) XML has the concept of a schema XML has the concept of a schema DTD and the more expressive XML Schema DTD and the more expressive XML Schema XML is a data model XML is a data model Similar to the semistructured data model Similar to the semistructured data model XML supports internationalization (Unicode) and platform independence (an XML file is just a character file) XML supports internationalization (Unicode) and platform independence (an XML file is just a character file)Unicode
6 XML is the Standard for Data Exchange Web services (e.g., ecommerce) require exchanging data between various applications that run on different platforms Web services (e.g., ecommerce) require exchanging data between various applications that run on different platforms XML (augmented with namespaces) is the preferred syntax for data exchange on the Web XML (augmented with namespaces) is the preferred syntax for data exchange on the Web
7 XML is not Alone XML Schemas strengthen the data-modeling capabilities of XML (in comparison to XML with only DTDs) XML Schemas strengthen the data-modeling capabilities of XML (in comparison to XML with only DTDs) XPath is a language for accessing parts of XML documents XPath is a language for accessing parts of XML documents XLink and XPointer support cross-references XLink and XPointer support cross-references XSLT is a language for transforming XML documents into other XML documents (including XHTML, for displaying XML files) XSLT is a language for transforming XML documents into other XML documents (including XHTML, for displaying XML files) Limited styling of XML can be done with CSS alone Limited styling of XML can be done with CSS alone XQuery is a lanaguage for querying XML documents XQuery is a lanaguage for querying XML documents
8 The Two Facets of XML Some XML files are just text documents with tags that denote their structure and include some metadata (e.g., an attribute that gives the name of the person who did the proofreading) Some XML files are just text documents with tags that denote their structure and include some metadata (e.g., an attribute that gives the name of the person who did the proofreading) See an example on the next slide See an example on the next slide XML is a subset of SGML (Standard Generalized Markup Language) XML is a subset of SGML (Standard Generalized Markup Language) Other XML documents are similar to database files (e.g., an address book) Other XML documents are similar to database files (e.g., an address book)
9 XML can Describe the Structure of a Document TCP/IP Illustrated TCP/IP Illustrated <author><last>Stevens</last><first>W.</first></author><publisher>Addison-Wesley</publisher><price>65.95</price></book>
10 XML Syntax W3Schools Resources on XML Syntax W3Schools Resources on XML Syntax
11 The Structure of XML XML consists of tags and text XML consists of tags and text Tags come in pairs... Tags come in pairs... They must be properly nested They must be properly nested good good bad bad (You can’t do in HTML)
12 A Useful Abbreviation Abbreviating elements with empty contents: for for For example: Lisa Simpson Lisa Simpson... Note that a tag may have a set of attributes, each consisting of a name and a value
13 XML Text XML has only one “basic” type – text It is bounded by tags, e.g., The Big Sleep The Big Sleep 1935 – 1935 is still text 1935 – 1935 is still text XML text is called PCDATA XML text is called PCDATA (for parsed character data) (for parsed character data) It uses a 16-bit encoding, e.g., \&\#x0152 for the Hebrew letter Mem It uses a 16-bit encoding, e.g., \&\#x0152 for the Hebrew letter Mem
14 XML Structure Nesting tags can be used to express various structures, e.g., a tuple (record): Nesting tags can be used to express various structures, e.g., a tuple (record): Lisa Simpson
15 XML Structure (cont’d) We can represent a list by using the same tag repeatedly: We can represent a list by using the same tag repeatedly: …
16 XML Structure (cont’d) Donald Duck Miki Mouse
17 Terminology The segment of an XML document between an opening and a corresponding closing tag is called an element Bart Simpson 02 – – element element, a sub-element of not an element
18 An XML Document is a Tree person name tel Bart Simpson 02 – – Leaves are either empty or contain PCDATA
19 Mixed Content An element may contain a mixture of sub- elements and PCDATA British Airways British Airways World’s favorite World’s favorite airline
20 The Header Tag Standalone=“no” means that there is an external DTD Standalone=“no” means that there is an external DTD You can leave out the encoding attribute and the processor will use the UTF-8 default You can leave out the encoding attribute and the processor will use the UTF-8 default
21 Processing Instructions Hello, world! Hello, world! <?pi-without-data?>
22 Using CDATA Entering a Kennel Club Member Entering a Kennel Club Member Enter the member by the name on his or her papers. Use the NAME tag. The NAME tag has two attributes. Common (all in lowercase, please!) is the dog's call name. Breed (also in all lowercase) is the dog's breed. Please see the breed reference guide for acceptable breeds. Your entry should look something like this: Enter the member by the name on his or her papers. Use the NAME tag. The NAME tag has two attributes. Common (all in lowercase, please!) is the dog's call name. Breed (also in all lowercase) is the dog's breed. Please see the breed reference guide for acceptable breeds. Your entry should look something like this: Sir Fredrick of Ledyard's End ]]> Sir Fredrick of Ledyard's End ]]> We want to see the text as is, even though it includes tags
23 A Complete XML Document ng/fa05/AdvDb/Lectures/bib.xml ng/fa05/AdvDb/Lectures/bib.xml
24 Well-Formed XML Documents An XML document (with or without a DTD) is well-formed if An XML document (with or without a DTD) is well-formed if Tags are syntactically correct Tags are syntactically correct Every tag has an end tag Every tag has an end tag Tags are properly nested Tags are properly nested There is a root tag There is a root tag A start tag does not have two occurrences of the same attribute A start tag does not have two occurrences of the same attribute An XML document must be well formed
25 Representing relational databases A relational database for school: student:course: enroll:
26 XML representation <school> Joe 3.0 Joe 3.0 </student> Mary 4.0 Mary 4.0 </student> DB 3.0 DB 3.0 </course> Web 3.0 Web 3.0 </course>
27 XML representation <enroll> </enroll><enroll> </enroll><enroll> </enroll></school>