Presentation is loading. Please wait.

Presentation is loading. Please wait.

XML – Basic Concepts (modified version from Dr. Praveen Madiraju)

Similar presentations


Presentation on theme: "XML – Basic Concepts (modified version from Dr. Praveen Madiraju)"— Presentation transcript:

1 XML – Basic Concepts (modified version from Dr. Praveen Madiraju)
2018, Fall Pusan National University Ki-Joune Li

2 W3SCHOOLS.COM a very nice material is found at

3 XML vs. HTML HTML is a HyperText Markup language
Designed for a specific application, namely, presenting and linking hypertext documents XML describes structure and content (“semantics”) The presentation is defined separately from the structure and the content

4 An Address Book as an XML document
<addresses> <person> <name> Donald Duck</name> <tel> </tel> < > </ > </person> <name> Miki Mouse</name> <tel> </tel> </addresses>

5 Main Features of XML No fixed set of tags
New tags can be added for new applications An agreed upon set of tags can be used in many applications Namespaces facilitate uniform and coherent descriptions of data For example, a namespace for address books determines whether to use <tel> or <phone>

6 Main Features of XML (cont’d)
XML has the concept of a schema DTD and the more expressive XML Schema XML is a data model Similar to the semistructured data model cf. DB Schema XML supports internationalization (Unicode) and platform independence (an XML file is just a character file)

7 XML is the Standard for Data Exchange
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

8 XML is not Alone 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 XLink and XPointer support cross-references 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 XQuery is a lanaguage for querying XML documents

9 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) See an example on the next slide XML is a subset of SGML (Standard Generalized Markup Language) Other XML documents are similar to database files (e.g., an address book)

10 XML can Describe the Structure of a Document
<book year="1994"> <title>TCP/IP Illustrated</title> <author> <last>Stevens</last> <first>W.</first> </author> <publisher>Addison-Wesley</publisher> <price>65.95</price> </book>

11 W3Schools Resources on XML Syntax

12 The Structure of XML XML consists of tags and text
Tags come in pairs <date> ... </date> They must be properly nested good <date> ... <day> ... </day> ... </date> bad <date> ... <day> ... </date>... </day> (You can’t do <i> ... <b> ... </i> ...</b> in HTML)

13 A Useful Abbreviation Abbreviating elements with empty contents: <br/> for <br></br> <hr width=“10”/> for <hr width=“10”></hr> For example: <family> <person id = “lisa”> <name> Lisa Simpson </name> <mother idref = “marge”/> <father idref = “homer”/> </person> ... </family> Note that a tag may have a set of attributes, each consisting of a name and a value

14 XML Text XML has only one “basic” type – text
It is bounded by tags, e.g., <title> The Big Sleep </title> <year> 1935 </ year> – 1935 is still text XML text is called PCDATA (for parsed character data)

15 XML Structure Nesting tags can be used to express various structures, e.g., a tuple (record): <person> <name> Lisa Simpson</name> <tel> </tel> <tel> </tel> < > </ > </person>

16 XML Structure (cont’d)
We can represent a list by using the same tag repeatedly: <addresses> <person> … </person> </addresses>

17 XML Structure (cont’d)
<addresses> <person> <name> Donald Duck</name> <tel> </tel> < > </ > </person> <name> Miki Mouse</name> <tel> </tel> </addresses>

18 Terminology The segment of an XML document between an opening and a corresponding closing tag is called an element element element, a sub-element of <person> <name> Bart Simpson </name> <tel> 02 – </tel> <tel> 051 – </tel> < > </ > </person>

19 An XML Document is a Tree
person name tel tel Bart Simpson 051 – 02 – Leaves are either empty or contain PCDATA

20 Mixed Content <airline>
An element may contain a mixture of sub-elements and PCDATA <airline> <name> British Airways </name> <motto> World’s <dubious> favorite</dubious> airline </motto> </airline>

21 XML Attributes XML elements can have attributes, just like HTML:
Attributes are designed to contain data related to a specific element. Must be quoted Example <person gender="female"> Attributes vs. Elements: Example <person>   <gender>female</gender> </person> To consider attributes cannot contain multiple values (elements can) attributes cannot contain tree structures (elements can) attributes are not easily expandable (for future changes)

22 XML Attributes as Metadata
<messages>   <note id="501">     <to>Tove</to>     <from>Jani</from>     <heading>Reminder</heading>     <body>Don't forget me this weekend!</body>   </note>   <note id="502">     <to>Jani</to>     <from>Tove</from>     <heading>Re: Reminder</heading>     <body>I will not</body>   </note> </messages>

23 XML Namespaces Using a Prefix  leads to a conflict
<table>   <tr>     <td>Apples</td>     <td>Bananas</td>   </tr> </table> <table>   <name>African Table </name>   <width>80</width>   <length>120</length> </table>  leads to a conflict Using a Prefix <root  xmlns:h=" xmlns:f=" <h:table>   <h:tr>     <h:td>Apples</h:td>     <h:td>Bananas</h:td>   </h:tr> </h:table> <f:table>   <f:name>African Coffee</f:name>   <f:width>80</f:width>   <f:length>120</f:length> </f:table> </root>

24 The Header Tag <?xml version="1.0" standalone="yes/no" encoding="UTF-8"?> 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

25 Processing Instructions
<?xml version="1.0"?> <?xml-stylesheet  href="doc.xsl" type="text/xsl"?> <!DOCTYPE doc SYSTEM "doc.dtd"> <doc>Hello, world!<!-- Comment 1 --></doc> <?pi-without-data?> <!-- Comment 2 --> <!-- Comment 3 -->

26 Well-Formed XML Documents
An XML document (with or without a DTD) is well- formed if Tags are syntactically correct Every tag has an end tag Tags are properly nested There is a root tag A start tag does not have two occurrences of the same attribute An XML document must be well formed

27 Representing relational databases
A relational database for school: student: course: enroll:

28 XML representation of relational DB
<school> <student id=“001”> <name> Joe </name> <gpa> </gpa> </student> <student id=“002”> <name> Mary </name> <gpa> </gpa> <course cno=“331”> <title> DB </title> <credit> </credit> </course> <course cno=“350”> <title> Web </title> <credit> 3.0 </credit> <enroll> <id> 001 </id> <cno> </cno> </enroll> <id> 001 </id> <cno> </cno> <id> 002 </id> <cno> </cno> </school>


Download ppt "XML – Basic Concepts (modified version from Dr. Praveen Madiraju)"

Similar presentations


Ads by Google