1 / 26

Chapter 23 XML

Maziar Sanaii Ashtiani – 105405 SCT – EMU, Fall 2011/12. Chapter 23 XML. Introduction and Motivation. HTTP Standard Generalized Markup Language eXtensible Markup Language Useful as a data format to exchange between apps Markup means something not mentioned in the document

montana
Télécharger la présentation

Chapter 23 XML

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Maziar Sanaii Ashtiani – 105405 SCT – EMU, Fall 2011/12 Chapter 23XML

  2. Introduction and Motivation • HTTP • Standard Generalized Markup Language • eXtensible Markup Language • Useful as a data format to exchange between apps • Markup means something not mentioned in the document • Has tags enclosed n angle brackets • <title>Database Systems Concepts</title>

  3. Freedom <university> <department> <dept name> Comp. Sci. </dept name> <building> Taylor </building> <budget> 100000 </budget> </department> <course> <course id> CS-101 </course id> <title> Intro. to Computer Science </title> <dept name> Comp. Sci </dept name> <credits> 4 </credits> </course> <instructor> <IID> 10101 </IID> <name> Srinivasan </name> <dept name> Comp. Sci. </dept name> <salary> 65000 </salary> </instructor> <teaches> <IID> 10101 </IID> <course id> CS-101 </course id> </teaches> </university>

  4. Advantages • Tags are self documenting • No rigid format • Can evolve over time • Nested structures • Widely accepted • Lots of tools XML has become THE dominant format for data exchange

  5. Structure • Elements • Single root • Proper nesting • <course> . . . <title> . . . </title> .. . </course> • <course> . . . <title> . . . </course> ... </title> • Text in the context of an element • May be mixed with subelements • Nesting to avoid joins (fig. 23.5, 23.6)

  6. Structure (Cont’d) • Attributes • name= value • Strings • Useful as identifiers • Namespace • <university xmlns:yale=“http://www.yale.edu”> • Literal values • <![CDATA[<course> · · ·</course>]]>

  7. XML Document Schema • Databases have schemas • XML • Document Type Definition • XML Schema • Relax NG

  8. DTD <!DOCTYPE university [ <!ELEMENT university ( (department|course|instructor|teaches)+)> <!ELEMENT department ( dept name, building, budget)> <!ELEMENT course ( course id, title, dept name, credits)> <!ELEMENT instructor (IID, name, dept name, salary)> <!ELEMENT teaches (IID, course id)> <!ELEMENT dept name( #PCDATA )> <!ELEMENT building( #PCDATA )> <!ELEMENT budget( #PCDATA )> <!ELEMENT course id ( #PCDATA )> <!ELEMENT title ( #PCDATA )> <!ELEMENT credits( #PCDATA )> <!ELEMENT IID( #PCDATA )> <!ELEMENT name( #PCDATA )> <!ELEMENT salary( #PCDATA )> ] >

  9. DTD (Cont’d) <!DOCTYPE university-3 [ <!ELEMENT university ( (department|course|instructor)+)> <!ELEMENT department ( building, budget )> <!ATTLIST department dept_nameID #REQUIRED > <!ELEMENT course (title, credits )> <!ATTLIST course course_idID #REQUIRED dept_nameIDREF #REQUIRED instructors IDREFS #IMPLIED > <!ELEMENT instructor ( name, salary )> <!ATTLIST instructor IID ID #REQUIRED > deptname IDREF #REQUIRED > · · · declarations for title, credits, building,budget, name and salary · · · ] >

  10. DTD Limitations • No constraints • Data verification needed • No limit over occurrence • Lack of typing for ID and IDREF

  11. XML Schema • Result of deficiencies in DTD • Has string, integer, decimal,… • User defined types

  12. XML Schema (Cont’d) <xs:schemaxmlns:xs=“http://www.w3.org/2001/XMLSchema”> <xs:element name=“university” type=“universityType” /> <xs:element name=“department”> <xs:complexType> <xs:sequence> <xs:element name=“dept name” type=“xs:string”/> <xs:element name=“building” type=“xs:string”/> <xs:element name=“budget” type=“xs:decimal”/> </xs:sequence> </xs:complexType> </xs:element> <xs:element name=“course”> <xs:element name=“course id” type=“xs:string”/> <xs:element name=“title” type=“xs:string”/> <xs:element name=“dept name” type=“xs:string”/> <xs:element name=“credits” type=“xs:decimal”/> </xs:element> <xs:complexType name=“UniversityType”> <xs:sequence> <xs:element ref=“department” minOccurs=“0” maxOccurs=“unbounded”/> <xs:element ref=“course” minOccurs=“0” maxOccurs=“unbounded”/> <xs:element ref=“instructor” minOccurs=“0” maxOccurs=“unbounded”/> <xs:element ref=“teaches” minOccurs=“0” maxOccurs=“unbounded”/> </xs:sequence> </xs:complexType> </xs:schema> • <xs:attribute name = “dept name”/>

  13. XML Schema (Cont’d) • PK <xs:key name = “deptKey”> <xs:selectorxpath = “/university/department”/> <xs:fieldxpath = “dept name”/> </xs:key> • FK <xs: name = “courseDeptFKey” refer=“deptKey”> <xs:selectorxpath = “/university/course”/> <xs:fieldxpath = “dept name”/> </xs:keyref>

  14. XML Schema Benefits • Constraints • User-defined types • PK and FK • Integrated namespaces • Min and Max values • Type extension by inheritence

  15. Query and Transformation • XPath • Language for path expressions • XQuery • Standard language for querying XML • Modeled after SQL but different • Deal with nested XML data

  16. Tree Model of XML and XPath • Trees and nodes • Elements and attributes • XPath 2.0 • /university-3/instructor/name • <name>Srinivasan</name> • <name>Brandt</name>

  17. XPath features • Selection • /university-3/course[credits >= 4]/@course id • Functions • Count() • /university-2/instructor[count(./teaches/course)> 2] • id(“foo”) • Union “|” • …

  18. XQuery • W3C • XQuery 1.0 • For • Let • Where • Order by • Return

  19. XQuery (Cont’d) for $x in /university-3/course let $courseId := $x/@course_id where $x/credits > 3 return <course_id> { $courseId } </course_id> is equivalent to for $x in /university-3/course[credits > 3] return <course_id> { $x/@course id } </course_id>

  20. XQuery Joins for $c in /university/course, $i in /university/instructor, $t in /university/teaches where $c/course_id= $t/course id and $t/IID = $i/IID return <course_instructor> { $c $i } </course_instructor> which is equivalent to for $c in /university/course, $i in /university/instructor, $t in /university/teaches[ $c/course id= $t/course id and $t/IID = $i/IID] return <course_instructor> { $c $i } </course_instructor>

  21. Functions and Types declare function local:dept_courses($iid as xs:string) as element(course)* { for $i in /university/instructor[IID = $iid], $c in /university/courses[dept name = $i/dept_name] return $c }

  22. API to XML • Document Object Model • JAVA DOM API • Simple API for XML • Event model

  23. Storage of XML Data • Non-relational Data Stores • Flat files (NO ACID) • XML Database • DOM C++-based

  24. Storage of XML Data (Cont’d) • Relational Databases • Store as string • clob • Tree Representation • Map to Relations • Publishing and Shredding XML Data • Native Storage within Relational Database

  25. SQL/XML select xmlelement(name “course”, xmlattributes(course id as course id, dept name as dept name), xmlelement(name “title”, title), xmlelement(name “credits”, credits)) from course

  26. XML Applications • Storing Data With Complex Structure • ODF • OOXML • Standardized Data Exchange Format • B2B • Web Services – HTTP • SOAP • WSDL • Data Mediation – Wrappers

More Related