CS 157B: Database Management Systems II February 20 Class Meeting Department of Computer Science San Jose State University Spring 2013 Instructor: Ron.

Slides:



Advertisements
Similar presentations
XML Examples. Bank Information Basic structure: A-101 Downtown 500 … Johnson Alma Surrey … A-101 Johnson …
Advertisements

XQuery John Annechino Steven Pow. Agenda What is XQuery? Uses of XQuery XQuery vs. XSLT Syntax –Built-In Functions –FLWOR –if-then-else –User-Defined.
XQUERY. What is XQuery? XQuery is the language for querying XML data The best way to explain XQuery is to say that XQuery is to XML what SQL is to database.
1 XQuery Web and Database Management System. 2 XQuery XQuery is to XML what SQL is to database tables XQuery is designed to query XML data What is XQuery?
Friday, September 4 th, 2009 The Systems Group at ETH Zurich XML and Databases Exercise Session 6 courtesy of Ghislain Fourny/ETH © Department of Computer.
Introduction to XQuery and eXist XQuery workshop April 2006.
Introduction to XQuery and eXist DSA. XSLT Tutorial Problems Bad language : – No ! – for XML schema –Some XSLT engines tolerant of extra tags (permissive),
1 COS 425: Database and Information Management Systems XML and information exchange.
XML Introduction What is XML –XML is the eXtensible Markup Language –Became a W3C Recommendation in 1998 –Tag-based syntax, like HTML –You get to make.
XML Technologies and Applications Rajshekhar Sunderraman Department of Computer Science Georgia State University Atlanta, GA 30302
CS 160: Software Engineering August 27 Class Meeting Department of Computer Science San Jose State University Fall 2014 Instructor: Ron Mak
XMLII XSchema XSchema XQuery XQuery. XML Schema XML Schema is a more sophisticated schema language which addresses the drawbacks of DTDs. Supports XML.
CS 174: Web Programming April 16 Class Meeting Department of Computer Science San Jose State University Spring 2015 Instructor: Ron Mak
XQuery Your gateway to manipulating XML in SQL Server 2005.
2.2 SQL Server 2005 的 XML 支援功能. Overview XML Enhancements in SQL Server 2005 The xml Data Type Using XQuery.
CS 157B: Database Management Systems II February 27 Class Meeting Department of Computer Science San Jose State University Spring 2013 Instructor: Ron.
Lecture 7 of Advanced Databases XML Querying & Transformation Instructor: Mr.Ahmed Al Astal.
Lecture 6 of Advanced Databases XML Schema, Querying & Transformation Instructor: Mr.Ahmed Al Astal.
Maziar Sanaii Ashtiani – SCT – EMU, Fall 2011/12.
Comparing XSLT and XQuery Michael Kay XTech 2005.
Lecture 6 of Advanced Databases XML Querying & Transformation Instructor: Mr.Eyad Almassri.
VICTORIA UNIVERSITY OF WELLINGTON Te Whare Wananga o te Upoko o te Ika a Maui SWEN 432 Advanced Database Design and Implementation An Introduction to XQuery.
An Introduction to XML Presented by Scott Nemec at the UniForum Chicago meeting on 7/25/2006.
Session II Chapter 2 – Chapter 2 – XSLhttp://
VICTORIA UNIVERSITY OF WELLINGTON Te Whare Wananga o te Upoko o te Ika a Maui SWEN 432 Advanced Database Design and Implementation An Introduction to XQuery.
CS 157B: Database Management Systems II May 8 Class Meeting Department of Computer Science San Jose State University Spring 2013 Instructor: Ron Mak
Company LOGO OODB and XML Database Management Systems – Fall 2012 Matthew Moccaro.
 XML is designed to describe data and to focus on what data is. HTML is designed to display data and to focus on how data looks.  XML is created to structure,
CS 174: Web Programming September 23 Class Meeting Department of Computer Science San Jose State University Fall 2015 Instructor: Ron Mak
Introduction to XQuery Bun Yue Professor, CS/CIS UHCL.
CS 157B: Database Management Systems II February 6 Class Meeting Department of Computer Science San Jose State University Spring 2013 Instructor: Ron Mak.
1 XSLT An Introduction. 2 XSLT XSLT (extensible Stylesheet Language:Transformations) is a language primarily designed for transforming the structure of.
CS 235: User Interface Design September 22 Class Meeting Department of Computer Science San Jose State University Fall 2014 Instructor: Ron Mak
VICTORIA UNIVERSITY OF WELLINGTON Te Whare Wananga o te Upoko o te Ika a Maui SWEN 432 Advanced Database Design and Implementation Exam and Lecture Overview.
CS 160: Software Engineering October 6 Class Meeting Department of Computer Science San Jose State University Fall 2014 Instructor: Ron Mak
CS 157B: Database Management Systems II February 25 Class Meeting Department of Computer Science San Jose State University Spring 2013 Instructor: Ron.
CS 174: Web Programming September 2 Class Meeting Department of Computer Science San Jose State University Fall 2015 Instructor: Ron Mak
XQuery Leah Andrews. Overview  Queries data stored in XML trees  Declarative  High-level  Functional (no side effects)  Strongly typed  Nodes 
CS 153: Concepts of Compiler Design September 16 Class Meeting Department of Computer Science San Jose State University Fall 2015 Instructor: Ron Mak
[ Part III of The XML seminar ] Presenter: Xiaogeng Zhao A Introduction of XQL.
CS 157B: Database Management Systems II April 3 Class Meeting Department of Computer Science San Jose State University Spring 2013 Instructor: Ron Mak.
CS 153: Concepts of Compiler Design October 10 Class Meeting Department of Computer Science San Jose State University Fall 2015 Instructor: Ron Mak
CS 157B: Database Management Systems II February 11 Class Meeting Department of Computer Science San Jose State University Spring 2013 Instructor: Ron.
© 2006 Altova GmbH. All Rights Reserved. Altova ® Product Line Overview.
CS 153: Concepts of Compiler Design October 21 Class Meeting Department of Computer Science San Jose State University Fall 2015 Instructor: Ron Mak
CS 157B: Database Management Systems II February 18 Class Meeting Department of Computer Science San Jose State University Spring 2013 Instructor: Ron.
CMPE 226 Database Systems November 4 Class Meeting Department of Computer Engineering San Jose State University Fall 2015 Instructor: Ron Mak
CS 174: Web Programming November 4 Class Meeting Department of Computer Science San Jose State University Spring 2015 Instructor: Ron Mak
CS 157B: Database Management Systems II February 13 Class Meeting Department of Computer Science San Jose State University Spring 2013 Instructor: Ron.
XML Query: xQuery Reference: Xquery By Priscilla Walmsley, Published by O’Reilly.
Friday, September 4 th, 2009 The Systems Group at ETH Zurich XML and Databases Exercise Session 5 courtesy of Ghislain Fourny/ETH © Department of Computer.
CS 157B: Database Management Systems II April 10 Class Meeting Department of Computer Science San Jose State University Spring 2013 Instructor: Ron Mak.
CS 157B: Database Management Systems II April 22 Class Meeting Department of Computer Science San Jose State University Spring 2013 Instructor: Ron Mak.
CS 152: Programming Language Paradigms April 7 Class Meeting Department of Computer Science San Jose State University Spring 2014 Instructor: Ron Mak
CMPE 226 Database Systems April 19 Class Meeting Department of Computer Engineering San Jose State University Spring 2016 Instructor: Ron Mak
CMPE 226 Database Systems November 4 Class Meeting Department of Computer Engineering San Jose State University Fall 2015 Instructor: Ron Mak
CS 160 and CMPE/SE 131 Software Engineering March 15 Class Meeting Department of Computer Science Department of Computer Engineering San José State University.
CS 152: Programming Language Paradigms February 12 Class Meeting Department of Computer Science San Jose State University Spring 2014 Instructor: Ron Mak.
XQuery 1.0: An XQL Query Language Attempt by W3C at a standard query language for XML. Has been called the “SQL.
XML: Extensible Markup Language
Querying and Transforming XML Data
Session IV Chapter 16 – XQuery
{ XML Technologies } BY: DR. M’HAMED MATAOUI
Querying XML XQuery.
Querying XML XQuery.
2/18/2019.
CMPE/SE 131 Software Engineering March 9 Class Meeting
CMPE 152: Compiler Design February 21/26 Lab
Session II Chapter 16 – XQuery
XML and Databases Exercise Session 10 courtesy of Ghislain Fourny
Presentation transcript:

CS 157B: Database Management Systems II February 20 Class Meeting Department of Computer Science San Jose State University Spring 2013 Instructor: Ron Mak

Department of Computer Science Spring 2013: February 20 CS 157B: Database Management Systems II © R. Mak 2 Project #2  Due: Friday, March 1.  Experience: Writing XML schemas Validating XML documents Marshalling and unmarshalling XML data XQuery Altova XMLSpy tool  Download the Altova XMLSpy 2013 tool from: Evaluation good for 30 days. _

Department of Computer Science Spring 2013: February 20 CS 157B: Database Management Systems II © R. Mak 3 XMLSpy XQuery Tutorial  How to edit, debug, and execute XQuery with XMLSpy YouTube video :

Department of Computer Science Spring 2013: February 20 CS 157B: Database Management Systems II © R. Mak 4 XQuery 1.0  A query language used to: Select content from an XML data source. Transform the content. Return the content in some format (XML, HTML,...). Uses XPath expressions.  Analogous to SQL for relational database tables.  Compact and easy to learn. Does not use the XML syntax.

Department of Computer Science Spring 2013: February 20 CS 157B: Database Management Systems II © R. Mak 5 XQuery Design XML Schemas Using UML Ayesha Malik Design service-oriented architecture frameworks with J2EE technology Naveen Balani Advance DAO Programming Sean Sullivan XML document adapted from the book Pro XML Development with Java Technology, by Ajay Vohra and Deepak Vohra, Apress, 2006 catalog.xql

Department of Computer Science Spring 2013: February 20 CS 157B: Database Management Systems II © R. Mak 6 XQuery Scripts  XQuery queries are kept in script files. Convention: Use the.xql suffix in the file name.  Example: Return the entire node tree from catalog.xml : The first line is mandatory (and won’t be shown in subsequent examples). _ xquery version "1.0"; doc("catalog.xml") xquery version "1.0";

Department of Computer Science Spring 2013: February 20 CS 157B: Database Management Systems II © R. Mak 7 XQuery Scripts  More examples: Return only the articles. Return articles whose titles contain the word “Design”. Return the articles that were written in the year doc("catalog.xml") //article doc("catalog.xml") //article/title[contains(., "Design")] doc("catalog.xml") "2003")]

Department of Computer Science Spring 2013: February 20 CS 157B: Database Management Systems II © R. Mak 8 FLWOR Expressions  Pronounced “flower”.  XQuery expressions can contain For (loops) Let (local variables) Where Order Return  Example: for $art in doc("catalog.xml") //article where "2003") return $art example-1.xql XMLSpy demo

Department of Computer Science Spring 2013: February 20 CS 157B: Database Management Systems II © R. Mak 9 FLWOR Expressions  Example: for $art in doc("catalog.xml") //article let $d := where contains($d, "2003") order by $art/title return ($art/title, $art/author) example-2.xql Note the := Note the parentheses and comma! A return clause can return only one expression. XMLSpy demo

Department of Computer Science Spring 2013: February 20 CS 157B: Database Management Systems II © R. Mak 10 FLWOR Expressions { for $art in doc("catalog.xml") //article let $d := where contains($d, "2003") order by $art/title return {$art/title, $art/author} } example-3.xql Note the curly braces and the comma! XMLSpy demo

Department of Computer Science Spring 2013: February 20 CS 157B: Database Management Systems II © R. Mak 11 FLWOR Expressions Ayesha Malik Sean Sullivan Mary Jane Naveen Balani directory.xml

Department of Computer Science Spring 2013: February 20 CS 157B: Database Management Systems II © R. Mak 12 FLWOR Expressions <xs:element ref="person" minOccurs="0" maxOccurs="unbounded"/> directory.xsd

Department of Computer Science Spring 2013: February 20 CS 157B: Database Management Systems II © R. Mak 13 FLWOR Expressions { for $person in doc("directory.xml") //person return ( { { if = "male") then "Mr." else "Ms." }, $person/name } ) } Note the comma! example-4.xql  Example: XMLSpy demo

Department of Computer Science Spring 2013: February 20 CS 157B: Database Management Systems II © R. Mak 14 FLWOR Expressions for $art in doc("catalog.xml") //article for $per in doc("directory.xml") //person let $addr := $per/ where $art/author = $per/name order by $art/title return ($art/title, $art/author, $addr) A join of two XML documents! example-5.xql  Example: XMLSpy demo

Department of Computer Science Spring 2013: February 20 CS 157B: Database Management Systems II © R. Mak 15 FLWOR Expressions { for $art in doc("catalog.xml") //article for $per in doc("directory.xml") //person let $addr := $per/ where $art/author = $per/name order by $art/title return { ($art/title, $art/author, $addr ) } } example-6.xql  Example: XMLSpy demo

Department of Computer Science Spring 2013: February 20 CS 157B: Database Management Systems II © R. Mak 16 User-Defined Functions in XQuery  Example: declare function local:splitter($name) { let $first := substring-before($name, ' ') let $last := substring-after ($name, ' ') return ( {$first}, {$last} ) }; NOTE! Standard XQuery functions Use the local namespace to prevent name clashes with standard functions.

Department of Computer Science Spring 2013: February 20 CS 157B: Database Management Systems II © R. Mak 17 User-Defined Functions in XQuery { for $art in doc("catalog.xml") //article for $per in doc("G:\Altova\Projects\directory.xml") //person let $addr := $per/ where $art/author = $per/name order by $art/title return { ($art/title, local:splitter($art/author), $addr ) } } example-7.xql XMLSpy demo

Department of Computer Science Spring 2013: February 20 CS 157B: Database Management Systems II © R. Mak 18 XML and Relational Databases  Modern RDBM systems provide XML support. For MySQL, see G:\Altova\Projects>mysql -u root -psesame --xml school mysql> select * from class; Data structures Java programming 101

Department of Computer Science Spring 2013: February 20 CS 157B: Database Management Systems II © R. Mak 19 XML and Relational Databases  Native XML support allows you to load and fetch XML data directly into and out of a relational database.  XQuery can directly query relational database tables. If database school contains table Teacher : However, the XQuery standard (as of version 1.0) doesn’t specify how to make a connection to a database.  There’s more to XQuery than can be presented in just one lecture! But this should give you a strong start for Project #2. _ let $teachers := collection("school.Teacher")