Lecture 21 XML querying. 2 XSL (eXtensible Stylesheet Language) In HTML, default styling is built into browsers as tag set for HTML is predefined and.

Slides:



Advertisements
Similar presentations
XML III. Learning Objectives Formatting XML Documents: Overview Using Cascading Style Sheets to format XML documents Using XSL to format XML documents.
Advertisements

XML: Extensible Markup Language
1 XML DTD & XML Schema Monica Farrow G30
1 COS 425: Database and Information Management Systems XML and information exchange.
Cornell CS 502 More XML XML schema, XPATH, XSLT CS 502 – Carl Lagoze – Cornell University.
XML –Query Languages, Extracting from Relational Databases ADVANCED DATABASES Khawaja Mohiuddin Assistant Professor Department of Computer Sciences Bahria.
XML Technologies and Applications Rajshekhar Sunderraman Department of Computer Science Georgia State University Atlanta, GA 30302
September 15, 2003Houssam Haitof1 XSL Transformation Houssam Haitof.
1 Print your own copy If you bring it along, hand in with your exam script Do not write anything extra or you will be penalized Student Name: Student Number:
1 Advanced Topics XML and Databases. 2 XML u Overview u Structure of XML Data –XML Document Type Definition DTD –Namespaces –XML Schema u Query and Transformation.
Processing of structured documents Spring 2003, Part 8 Helena Ahonen-Myka.
Manohar – Why XML is Required Problem: We want to save the data and retrieve it further or to transfer over the network. This.
Introduction to XPath Bun Yue Professor, CS/CIS UHCL.
SD2520 Databases using XML and JQuery
XMLII XSchema XSchema XQuery XQuery. XML Schema XML Schema is a more sophisticated schema language which addresses the drawbacks of DTDs. Supports XML.
Aalborg University – Department of Production XML Extensible Markup Language Kaj A. Jørgensen Aalborg University, Department of Production XML – Extensible.
10/06/041 XSLT: crash course or Programming Language Design Principle XSLT-intro.ppt 10, Jun, 2004.
XML Anisha K J Jerrin Thomas. Outline  Introduction  Structure of an XML Page  Well-formed & Valid XML Documents  DTD – Elements, Attributes, Entities.
Lecture 7 of Advanced Databases XML Querying & Transformation Instructor: Mr.Ahmed Al Astal.
Why XML ? Problems with HTML HTML design - HTML is intended for presentation of information as Web pages. - HTML contains a fixed set of markup tags. This.
Lecture 6 of Advanced Databases XML Schema, Querying & Transformation Instructor: Mr.Ahmed Al Astal.
VICTORIA UNIVERSITY OF WELLINGTON Te Whare Wananga o te Upoko o te Ika a Maui SWEN 432 Advanced Database Design and Implementation XML Schema 1 Lecturer.
Ertan Deniz Instructor.  XML Schema  Document Navigation (Xpath)  Document Transformation (XSLT)
McGraw-Hill/Irwin © 2004 by The McGraw-Hill Companies, Inc. All rights reserved. Schemas Ellen Pearlman Eileen Mullin Programming the Web Using XML.
TDDD43 XML and RDF Slides based on slides by Lena Strömbäck and Fang Wei-Kleiner 1.
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.
Introduction technology XSL. 04/11/2005 Script of the presentation Introduction the XSL The XSL standard Tools for edition of codes XSL Necessary resources.
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
XML Overview. Chapter 8 © 2011 Pearson Education 2 Extensible Markup Language (XML) A text-based markup language (like HTML) A text-based markup language.
1 CIS336 Website design, implementation and management (also Semester 2 of CIS219, CIS221 and IT226) Lecture 6 XSLT (Based on Møller and Schwartzbach,
Chapter 27 The World Wide Web and XML. Copyright © 2004 Pearson Addison-Wesley. All rights reserved.27-2 Topics in this Chapter The Web and the Internet.
Lecture 22 XML querying. 2 Example 31.5 – XQuery FLWOR Expressions ‘=’ operator is a general comparison operator. XQuery also defines value comparison.
JSTL, XML and XSLT An introduction to JSP Standard Tag Library and XML/XSLT transformation for Web layout.
CITA 330 Section 6 XSLT. Transforming XML Documents to XHTML Documents XSLT is an XML dialect which is declared under namespace "
XSLT Kanda Runapongsa Dept. of Computer Engineering Khon Kaen University.
Waqas Anwar Next SlidePrevious Slide. Waqas Anwar Next SlidePrevious Slide XML XML stands for EXtensible Markup Language.
Database Systems Part VII: XML Querying Software School of Hunan University
Copyright © 2004 Ramez Elmasri and Shamkant Navathe Elmasri/Navathe, Fundamentals of Database Systems, Fourth Edition Chapter 26-2 Introduction Although.
XML – Part III. The Element … This type of element either has the element content or the mixed content (child element and data) The attributes of the.
[ Part III of The XML seminar ] Presenter: Xiaogeng Zhao A Introduction of XQL.
Chapter 27 The World Wide Web and XML. Copyright © 2004 Pearson Addison-Wesley. All rights reserved.27-2 Topics in this Chapter The Web and the Internet.
1 Tutorial 14 Validating Documents with Schemas Exploring the XML Schema Vocabulary.
Tutorial 13 Validating Documents with Schemas
Jennifer Widom XML Data Introduction, Well-formed XML.
The Semistructured-Data Model Programming Languages for XML Spring 2011 Instructor: Hassan Khosravi.
XML and Database.
CS 157B: Database Management Systems II February 11 Class Meeting Department of Computer Science San Jose State University Spring 2013 Instructor: Ron.
COMP9321 Web Application Engineering Semester 2, 2015 Dr. Amin Beheshti Service Oriented Computing Group, CSE, UNSW Australia Week 4 1COMP9321, 15s2, Week.
XML Query: xQuery Reference: Xquery By Priscilla Walmsley, Published by O’Reilly.
More XML XPATH, XSLT CS 431 – February 23, 2005 Carl Lagoze – Cornell University.
Session 1 Module 1: Introduction to Data Integrity
Martin Kruliš by Martin Kruliš (v1.1)1.
Working with XML. Markup Languages Text-based languages based on SGML Text-based languages based on SGML SGML = Standard Generalized Markup Language SGML.
XPath --XML Path Language Motivation of XPath Data Model and Data Types Node Types Location Steps Functions XPath 2.0 Additional Functionality and its.
XP 1 XSLT II Robin Burke ECT 360. XP 2 Homework #4 Forgot we hadn't covered "choose" becomes extra credit My books.xml didn't include descriptions.
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)
 XML derives its strength from a variety of supporting technologies.  Structure and data types: When using XML to exchange data among clients, partners,
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.
1 XSLT XSLT (extensible stylesheet language – transforms ) is another language to process XML documents. Originally intended as a presentation language:
XML: Extensible Markup Language
Querying and Transforming XML Data
XML in Web Technologies
Data Modeling II XML Schema & JAXB Marc Dumontier May 4, 2004
Database Processing with XML
Prepared for Md. Zakir Hossain Lecturer, CSE, DUET Prepared by Miton Chandra Datta
XML Data Introduction, Well-formed XML.
More XML XML schema, XPATH, XSLT
Presentation transcript:

Lecture 21 XML querying

2 XSL (eXtensible Stylesheet Language) In HTML, default styling is built into browsers as tag set for HTML is predefined and fixed. Cascading Stylesheet Specification (CSS) provides alternative rendering for tags. Can also be used to render XML in a browser but cannot make structural alterations to a document. XSL created to define how XML data is rendered and to define how one XML document can be transformed into another document.

3 XSLT (XSL Transformations) A subset of XSL, XSLT is a language in both markup and programming sense, providing a mechanism to transform XML structure into either another XML structure, HTML, or any number of other text-based formats (such as SQL). XSLT’s main ability is to change the underlying structures rather than simply the media representations of those structures, as with CSS.

4 XSLT XSLT is important because it provides a mechanism for dynamically changing the view of a document and for filtering data. Also robust enough to encode business rules and it can generate graphics (not just documents) from data. Can even handle communicating with servers (scripting modules can be integrated into XSLT) and can generate the appropriate messages within body of XSLT itself.

5 XPath Declarative query language for XML that provides simple syntax for addressing parts of an XML document. Designed for use with XSLT (for pattern matching) and XPointer (for addressing). With XPath, collections of elements can be retrieved by specifying a directory-like path, with zero or more conditions placed on the path. Uses a compact, string-based syntax, rather than a structural XML-element based syntax, allowing XPath expressions to be used both in XML attributes and in URIs.

6 XPath

7 XML Schema XML schema is the definition (both in terms of its organization and its data types) of a specific XML structure. XML Schema language specifies how each type of element in schema is defined and the element’s data type. Schema is an XML document, and so can be edited and processed by same tools that read the XML it describes.

8 XML Schema – Simple Types Elements that do not contain other elements or attributes are of type simpleType. Attributes must be defined last:

9 XML Schema – Complex Types Elements that contain other elements are of type complexType. List of children of complex type are described by sequence element.

10 Cardinality Cardinality of an element can be represented using attributes minOccurs and maxOccurs. To represent an optional element, set minOccurs to 0; to indicate there is no maximum number of occurrences, set maxOccurs to “unbounded”. <xsd:element name=“DOB” type=“xsd:date” minOccurs = “0”/> <xsd:element name=“NOK” type=“xsd:string” minOccurs = “0” maxOccurs = “3”/>

11 References Can use references to elements and attribute definitions. …. If there are many references to STAFFNO, use of references will place definition in one place and improve the maintainability of the schema.

12 Defining New Types Can also define new data types to create elements and attributes. New type has been defined as a restriction of string (to have maximum length of 5 characters).

13 Groups Can define both groups of elements and groups of attributes. Group is not a data type but acts as a container holding a set of elements or attributes.

14 Constraints XML Schema provides XPath-based features for specifying uniqueness constraints and corresponding reference constraints that will hold within a certain scope.

15 Key Constraints Similar to uniqueness constraint except the value has to be non-null. Also allows the key to be referenced.

16 Resource Description Framework (RDF) Even XML Schema does not provide the support for semantic interoperability we required. For example, when two applications exchange information using XML, both agree on use and intended meaning of the document structure. Must first build a model of the domain of interest, to clarify what kind of data is to be sent from first application to second. However, as XML Schema just describes a grammar, there are many different ways to encode a specific domain model into an XML Schema, thereby losing the direct connection from the domain model to the Schema. Covered in Advance Web Technologies (Comp 318)

17 XML Query Languages Data extraction, transformation, and integration are well- understood database issues that rely on a query language. SQL and OQL do not apply directly to XML because of the irregularity of XML data. However, XML data similar to semistructured data. There are many semistructured query languages that can query XML documents, including XML-QL, UnQL, and XQL. All have notion of a path expression for navigating nested structure of XML.

18 XML Query Working Group W3C formed an XML Query Working Group in 1999 to produce a data model for XML documents, set of query operators on this model, and query language based on query operators. Queries operate on single documents or fixed collections of documents, and can select entire documents or subtrees of documents that match conditions based on document content/structure. Queries can also construct new documents based on what has been selected.

19 XML Query Working Group Ultimately, collections of XML documents will be accessed like databases. Working Group has produced several documents: XML Query (XQuery) Requirements; XML XQuery 1.0 and XPath 2.0 Data Model; XML XQuery 1.0 and XPath 2.0 Formal Semantics; XQuery 1.0 – A Query Language for XML; XML XQuery 1.0 and XPath 2.0 Functions and Operators; XSLT 2.0 and XPath 1.0 Serialization.

20 XML Query Requirements Specifies goals, usage scenarios, and requirements for XQuery Data Model and query language. For example: language must be declarative and must be defined independently of any protocols with which it is used; queries should be possible whether or not a schema exists; language must support both universal and existential quantifiers on collections and it must support aggregation, sorting, nulls, and be able to traverse inter- and intra-document references.

21 XQuery XQuery derived from XML query language called Quilt, which has borrowed features from XPath, XML-QL, SQL, OQL, Lorel, XQL, and YATL. Like OQL, XQuery is a functional language in which a query is represented as an expression. XQuery supports several kinds of expression, which can be nested (supporting notion of a subquery).

22 XQuery – Path Expressions Uses syntax of XPath. In XQuery, result of a path expression is ordered list of nodes, including their descendant nodes, ordered according to their position in original hierarchy, top-down, left-to-right order. Result of path expression may contain duplicate values. Each step in path expression represents movement through document in particular direction, and each step can eliminate nodes by applying one or more predicates.

23 XQuery – Path Expressions Result of each step is list of nodes that serves as starting point for next step. Path expression can begin with an expression that identifies a specific node, such as function doc(string), which returns root node of named document. Query can also contain path expression beginning with “/” or “//”, which represents an implicit root node determined by the environment in which query is executed.

24 Example 31.4 – XQuery Path Expressions Find staff number of first member of staff in our XML document. doc(“staff_list.xml”)/STAFFLIST/STAFF[1]//STAFFNO Four steps: first opens staff_list.xml and returns its document node; second uses /STAFFLIST to select STAFFLIST element at top; third locates first STAFF element that is child of root element; fourth finds STAFFNO elements occurring anywhere within this STAFF element.

25 Example 31.4 – XQuery Path Expressions Knowing structure of document, could also express this as: doc(“staff_list.xml”)//STAFF[1]/STAFFNO doc(“staff_list.xml”)/STAFFLIST/STAFF[1]/STAFFNO

26 Example 31.4 – XQuery Path Expressions Find staff numbers of first two members of staff. doc(“staff_list.xml”)/STAFFLIST/STAFF[1 TO 2]/ STAFFNO

27 Example 31.4 – XQuery Path Expressions Find surnames of staff at branch B005. doc(“staff_list.xml”)/STAFFLIST/ =“B005”]//LNAME Five steps: first two as before; third uses /STAFF to select STAFF elements within STAFFLIST element; fourth consists of predicate that restricts STAFF elements to those with branchNo attribute = B005; fifth selects LNAME element(s) occurring anywhere within these elements.

28 XQuery – FLWOR Expressions FLWOR (“flower”) expression is constructed from FOR, LET, WHERE, ORDER BY, RETURN clauses. FLWOR expression starts with one or more FOR or LET clauses in any order, followed by optional WHERE clause, optional ORDER BY clause, and required RETURN clause. FOR and LET clauses serve to bind values to one or more variables using expressions (e.g., path expressions). FOR used for iteration, associating each specified variable with expression that returns list of nodes. FOR clause can be thought of as iterating over nodes returned by its respective expression.

29 XQuery – FLWOR Expressions LET clause also binds one or more variables to one or more expressions but without iteration, resulting in single binding for each variable. Optional WHERE clause specifies one or more conditions to restrict tuples generated by FOR and LET. RETURN clause evaluated once for each tuple in tuple stream and results concatenated to form result. ORDER BY clause, if specified, determines order of the tuple stream which, in turn, determines order in which RETURN clause is evaluated using variable bindings in the respective tuples.

30 XQuery – FLWOR Expressions

31 Example 31.5 – XQuery FLWOR Expressions List staff with salary = £30,000. LET $SAL := RETURN doc(“staff_list.xml”)//STAFF[SALARY = $SAL] Note, predicate seems to compare an element (SALARY) with a value (30000). In fact, ‘=’ operator extracts typed value of element resulting in a decimal value in this case, which is then compared with