1 XQuery Syntax Dan McCreary May, 2011. Basic Syntax XQuery vs. XML Where do we put… –Curly braces "{" and "} " –Parenthesis " (" and ") " –Square Brackets.

Slides:



Advertisements
Similar presentations
XML-XSL Introduction SHIJU RAJAN SHIJU RAJAN Outline Brief Overview Brief Overview What is XML? What is XML? Well Formed XML Well Formed XML Tag Name.
Advertisements

XML Data Management 8. XQuery Werner Nutt. Requirements for an XML Query Language David Maier, W3C XML Query Requirements: Closedness: output must be.
Querying on the Web: XQuery, RDQL, SparQL Semantic Web - Spring 2006 Computer Engineering Department Sharif University of Technology.
XML: Extensible Markup Language
1 XSLT – eXtensible Stylesheet Language Transformations Modified Slides from Dr. Sagiv.
SPECIAL TOPIC XML. Introducing XML XML (eXtensible Markup Language) ◦A language used to create structured documents XML vs HTML ◦XML is designed to transport.
An Introduction to XML Based on the W3C XML Recommendations.
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?
Using oXygen Using oXygen to build and execute XQuery applications on eXist Date: September 2008 Dan McCreary President Dan McCreary & Associates
Paper by: A. Balmin, T. Eliaz, J. Hornibrook, L. Lim, G. M. Lohman, D. Simmen, M. Wang, C. Zhang Slides and Presentation By: Justin Weaver.
Working with JavaScript. 2 Objectives Introducing JavaScript Inserting JavaScript into a Web Page File Writing Output to the Web Page Working with Variables.
XP 1 Working with JavaScript Creating a Programmable Web Page for North Pole Novelties Tutorial 10.
Chapter 8 Arrays and Strings
XML –Query Languages, Extracting from Relational Databases ADVANCED DATABASES Khawaja Mohiuddin Assistant Professor Department of Computer Sciences Bahria.
C++ for Engineers and Scientists Third Edition
XML Technologies and Applications Rajshekhar Sunderraman Department of Computer Science Georgia State University Atlanta, GA 30302
17 Apr 2002 XML Stylesheets Andy Clark. What Is It? Extensible Stylesheet Language (XSL) Language for document transformation – Transformation (XSLT)
Overview of XPath Author: Dan McCreary Date: October, 2008 Version: 0.2 with TEI Examples M D.
Using XSLT and XPath to Enhance HTML Documents Reference: Roger L. Costello
4/20/2017.
Introduction to Programming Prof. Rommel Anthony Palomino Department of Computer Science and Information Technology Spring 2011.
IS432 Semi-Structured Data Lecture 5: XSLT Dr. Gamal Al-Shorbagy.
XSLT for Data Manipulation By: April Fleming. What We Will Cover The What, Why, When, and How of XSLT What tools you will need to get started A sample.
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.
XP New Perspectives on XML Tutorial 6 1 TUTORIAL 6 XSLT Tutorial – Carey ISBN
XP 1 CREATING AN XML DOCUMENT. XP 2 INTRODUCING XML XML stands for Extensible Markup Language. A markup language specifies the structure and content of.
WORKING WITH XSLT AND XPATH
Extensible Markup and Beyond
Created by, Author Name, School Name—State FLUENCY WITH INFORMATION TECNOLOGY Skills, Concepts, and Capabilities.
1 CIS336 Website design, implementation and management (also Semester 2 of CIS219, CIS221 and IT226) Lecture 6 XSLT (Based on Møller and Schwartzbach,
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,
Lecture 22 XML querying. 2 Example 31.5 – XQuery FLWOR Expressions ‘=’ operator is a general comparison operator. XQuery also defines value comparison.
XP Tutorial 10New Perspectives on Creating Web Pages with HTML, XHTML, and XML 1 Working with JavaScript Creating a Programmable Web Page for North Pole.
1 XSLT An Introduction. 2 XSLT XSLT (extensible Stylesheet Language:Transformations) is a language primarily designed for transforming the structure of.
CITA 330 Section 6 XSLT. Transforming XML Documents to XHTML Documents XSLT is an XML dialect which is declared under namespace "
Extensible Stylesheet Language Chao-Hsien Chu, Ph.D. School of Information Sciences and Technology The Pennsylvania State University XSL-FO XSLT.
XSLT Kanda Runapongsa Dept. of Computer Engineering Khon Kaen University.
Transforming Documents „a how-to of transforming xml documents“ Lecture on Walter Kriha.
Recursive Functions Creating Hierarchical Reports Date: 9/30/2008 Dan McCreary President Dan McCreary & Associates (952) M.
XQuery Functions Reusing XQuery Code Date: September, 2008 Dan McCreary President Dan McCreary & Associates (952) M D Metadata.
Keyword Searching Weighted Federated Search with Key Word in Context Date: 10/2/2008 Dan McCreary President Dan McCreary & Associates
1 Overview of XSL. 2 Outline We will use Roger Costello’s tutorial The purpose of this presentation is  To give a quick overview of XSL  To describe.
[ Part III of The XML seminar ] Presenter: Xiaogeng Zhao A Introduction of XQL.
XML query. introduction An XML document can represent almost anything, and users of an XML query language expect it to perform useful queries on whatever.
Using oXygen 12 with XQuery Using oXygen to build and execute XQuery XQuery applications on eXist Date: April 2011 Dan McCreary President Dan McCreary.
CS 157B: Database Management Systems II February 11 Class Meeting Department of Computer Science San Jose State University Spring 2013 Instructor: Ron.
IT ELECTIVE 2.  Web server Can refer to either the hardware (the computer) or the software (the computer application) that helps to deliver content that.
XSLT. XSLT stands for Extensible Stylesheet Language Transformations XSLT is used to transform XML documents into other kinds of documents. XSLT can produce.
XQuery Labs Basic Reporting Date: 9/29/2008 Dan McCreary President Dan McCreary & Associates (952) M D Metadata Solutions.
A Guide to SQL, Eighth Edition Chapter Four Single-Table Queries.
Lecture 23 XQuery 1.0 and XPath 2.0 Data Model. 2 Example 31.7 – User-Defined Function Function to return staff at a given branch. DEFINE FUNCTION staffAtBranch($bNo)
Tutorial 10 Programming with JavaScript. 2New Perspectives on HTML, XHTML, and XML, Comprehensive, 3rd Edition Objectives Learn the history of JavaScript.
Jackson, Web Technologies: A Computer Science Perspective, © 2007 Prentice-Hall, Inc. All rights reserved Chapter 7 Representing Web Data:
1 Types of Programming Language (1) Three types of programming languages 1.Machine languages Strings of numbers giving machine specific instructions Example:
XP Tutorial 10New Perspectives on HTML, XHTML, and DHTML, Comprehensive 1 Working with JavaScript Creating a Programmable Web Page for North Pole Novelties.
XML Schema – XSLT Week 8 Web site:
1 XSL Transformations (XSLT). 2 XSLT XSLT is a language for transforming XML documents into XHTML documents or to other XML documents. XSLT uses XPath.
XML Notes taken from w3schools. What is XML? XML stands for EXtensible Markup Language. XML was designed to store and transport data. XML was designed.
Rendering XML Documents ©NIITeXtensible Markup Language/Lesson 5/Slide 1 of 46 Objectives In this session, you will learn to: * Define rendering * Identify.
Basic concepts of C++ Presented by Prof. Satyajit De
XML: Extensible Markup Language
CHAPTER 7 DATABASE ACCESS THROUGH WEB
Unit 4 Representing Web Data: XML
Querying and Transforming XML Data
Chapter 7 Representing Web Data: XML
Querying XML XQuery.
Querying XML XQuery.
Introduction to C++ Programming
Sequences in XQuery Core data structure of XQuery Date: 8/25/2009
Presentation transcript:

1 XQuery Syntax Dan McCreary May, 2011

Basic Syntax XQuery vs. XML Where do we put… –Curly braces "{" and "} " –Parenthesis " (" and ") " –Square Brackets "[" and "]" –Single quotes: ' –Double quotes: " –Angle brackets " " 2

When to use a Semicolon ";" When do you add a semicolon to the end of a line? When do you leave it out? 3

Hello World xquery version "1.0"; let $message := 'Hello World' return {$message} 4

When can we return An XML document – A sequence –(1, 2, 3) Either? 5

6 XQuery’s Nested Structure XQueries have a alternating nested structure Interleave actual XML output and XQuery instructions XQuery Processor XML Processor

Interleaving XML and XQuery Use "{" to jump from XML into Xquery Use "}" to exit from XQuery 7 {xquery} {xquery} {xquery} Language parser

8 Example of Nested Structure xquery version “1.0”; let $collection := ‘/db/mycollection’ return My Report {for $i in collection($collection)/item return {$i/name/text()} } {$i/defintion/text()} Note that the inner blue XQuery areas always start and end with curly braces { }

9 XQuery FLOWR Expressions An XQuery FLOWR "expression" has five parts: for (optional) let (optional) order (optional) where (rarely used in native XML) return (required)

10 Predicates Things you add to an XPath expression to limit the selected items Like a SQL WHERE clause Find all the preferred terms in the glossary //term[published-indicator=‘true’] Return all terms that have published-indicator set to be true.

11 XQuery is Concise Michael Key "knight's tour" program Computes a knight's tour of the chessboard Complexity analysis –276 non-comment lines in XSLT 1.0 –159 non-comment lines in XSLT 2.0 –155 non-comment lines in XQuery See:

12 XQuery is a “Functional” Language XQuery (without the updates) does not change data It extracts XML and creates new XML Can be highly parallelized like Google’s MapReduce algorithm [Search YouTube Google Class]

13 Data Types Returned XQuery can return: –Text –CSV –Tables –Trees –Graphs Serialize options: See Walmsley p 293 declare option exist:serialize "method=html media-type=text/html indent=yes"; declare option exist:serialize "method=xml media-type=text/xml indent=yes"; declare option exist:serialize "method=text media-type=text/text indent=yes";

14 Returning Items in an Ordered List { for $term in collection($collection)/term return {$term/name/text()} } This query returns a HTML "Ordered List" of terms. 1.Term 1 2.Term 2 3.Term 3 4.Term 4

15 Example of For Over Collection for $term in collection('/db/apps/terms/data')/term let $collection := '/db/apps/terms/data’ for $term in collection($collection)/term This line may be omitted for clairity

16 Sample XQuery xquery version "1.0"; (: Example of report on all terms :) (: make the output XML :) declare option exist:serialize "method=xhtml media-type=text/xml indent=yes"; { (: select only xml documents with “term” as the root element :) for $term in collection($collection)/term return {$term/name/text()} }

17 Sample XQuery that returns XML xquery version "1.0"; (: make the output XML :) declare option exist:serialize "method=xml media-type=text/xml indent=yes"; let { for $term in collection('/db/apps/terms/data/')/term let $name := $term/name/text() return {$name} } Output: 01-xml.xq

18 Restricting Within an XPath xquery version "1.0"; declare option exist:serialize "method=xml media-type=text/xml indent=yes"; let $collection := '/db/apps/terms/data' return { for $term in collection($collection)/term [compare(substring($term/name/text(), 1), ‘a’)] order by $term return $term } Only find terms that begin with the letter “a”

19 Restricting Rows by Adding a “Where Clause” { for $term in collection('/db/mdr/glossaries/data')/Term where $term/PublishedIndicator/text() = ‘true' return {$term/TermName/text()} {$term/Definition/text()} } for $term in collection('/db/apps/terms/data')/term [$term/PublishedIndicator/text() = ‘true‘] Square Bracket Notation (always faster in native XML systems):

20 Using Complex Logic in Where Clause You can use any number of and/or statements in the where clause { for $term in collection('/db/mdr/glossaries/data')/Term where $term/ClassifierCode/text() = 'System‘ and $term/AssignedToCode/text() = ‘Dave‘ return {$term/TermName/text()} {$term/Definition/text()} }

21 Content Management “Macros” {cms:import-css-tables()} {cms:header()} {cms:breadcrumb-glossary()} XQuery macros are used to import snippets of canned XML or CSS text Change a single location and the entire web site look-and-feel changes Similar to server-side includes

22 Selecting Distinct Values xquery version "1.0"; declare names exist=" declare option exist:serialize "method=html media-type=text/html indent=yes"; import module names cms = " at "/db/mdr/cms/cms-module.xq"; let $title := 'My Report' return {$title} {cms:import-css-tables()} {cms:header()} {cms:breadcrumb-glossary()} Distinct ClassifierCode Values { for $classifier in distinct-values(collection('/db/mdr/glossaries/data/')/Term/ClassifierCode/text()) return {$classifier} }

23 Sample Results dave-p dennis-w ken-f kerek-t

24 Combine Outer Distinct Query xquery version "1.0"; declare names exist=" declare option exist:serialize "method=html media-type=text/html indent=yes"; import module names cms = " at "/db/mdr/cms/cms-module.xq"; let $title := 'My Report' return {$title} {cms:import-css-tables()} {cms:header()} {cms:breadcrumb-glossary()} { for $facilitator in distinct-values(collection('/db/mdr/glossaries/data/')/Term/AssignedToCode/text()) return Facilitator: {$facilitator} { for $term in collection('/db/mdr/glossaries/data/')/Term[AssignedToCode=$facilitator] return $term/TermName/text() }

25 Subsequence What to do when you have over 500 items returned by a query but you only want the first 50 items Similar to SELECT TOP in SQL for $term in subsequence($collection, 1, 50)/term return $term 1 is the starting term 50 is the number of term for $term in subsequence($collection, $start, $length)/term return $term

26 Try it out ex.xhtml

27 Computation and Transformation All computation is a type of transformation Compilers –Transform high-level languages into machine language Services –Transform an in input request into an output response Human Brain –Transform input stimuli into concept recognition via pattern matching –See On Intelligence by Jeff Hawkins

28 Sample Program The sum of 47 and 14 is 61 xquery version "1.0"; declare option exist:serialize "method=xml media-type=text/xml indent=yes"; let $dan := doc(' let $class := doc(' let $sum := $dan + $mdr return The sum of {$dan} and {$class} is {$sum}

29 Suggested Lab Use the "XQuery Sandbox" in eXist Try running some sample XQueries Use oXygen to run some simple queries

30 Questions?