XML Querying and Views Zachary G. Ives November 1, 2007

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

Inside an XSLT Processor Michael Kay, ICL 19 May 2000.
XML May 3 rd, XQuery Based on Quilt (which is based on XML-QL) Check out the W3C web site for the latest. XML Query data model –Ordered !
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.
XSL XSLT and XPath 11-Apr-17.
1 CP3024 Lecture 9 XML revisited, XSL, XSLT, XPath, XSL Formatting Objects.
Querying XML Zachary G. Ives University of Pennsylvania CIS 550 – Database & Information Systems October 6, 2003 Some slide content courtesy of Susan Davidson.
Querying XML: XQuery and XSLT Zachary G. Ives University of Pennsylvania CIS 550 – Database & Information Systems October 21, 2004 Some slide content courtesy.
XML, XPath, and XQuery Zachary G. Ives University of Pennsylvania CIS 550 – Database & Information Systems October 18, 2005 Some slide content courtesy.
XSL Concepts Lecture 7. XML Display Options What can XSL Transformations do? generation of constant text suppression of content moving text (e.g., exchanging.
XSL Unit 6 November 2. XSL –eXtensible Stylesheet Language –Basically a stylesheet for XML documents XSL has three parts: –XSLT –XPath –XSL-FO.
1 COS 425: Database and Information Management Systems XML and information exchange.
XML Querying and Views Zachary G. Ives University of Pennsylvania CIS 550 – Database & Information Systems November 1, 2005 Some slide content courtesy.
Views: Alternate Data Representations Zachary G. Ives University of Pennsylvania CIS 550 – Database & Information Systems November 2, 2004 Some slide content.
XML Technologies and Applications Rajshekhar Sunderraman Department of Computer Science Georgia State University Atlanta, GA 30302
XML Querying and Views Helena Galhardas DEI IST (slides baseados na disciplina CIS 550 – Database & Information Systems, Univ. Pennsylvania, Zachary Ives)CIS.
Querying XML: XPath, XQuery, and XSLT Zachary G. Ives University of Pennsylvania CIS 550 – Database & Information Systems October 27, 2005 Some slide content.
September 15, 2003Houssam Haitof1 XSL Transformation Houssam Haitof.
XML Transformations and Content-based Crawling Zachary G. Ives University of Pennsylvania CIS 455 / 555 – Internet and Web Systems August 7, 2015.
XML Schemas and Queries Zachary G. Ives University of Pennsylvania CIS 455 / 555 – Internet and Web Systems August 7, 2015.
MC 365 – Software Engineering Presented by: John Ristuccia Shawn Posts Ndi Sampson XSLT Introduction BCi.
ECA 228 Internet/Intranet Design I Intro to XSL. ECA 228 Internet/Intranet Design I XSL basics W3C standards for stylesheets – CSS – XSL: Extensible Markup.
Ertan Deniz Instructor.  XML Schema  Document Navigation (Xpath)  Document Transformation (XSLT)
XML-QL A Query Language for XML Charuta Nakhe
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.
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
Demystifying the eXtensible Markup Language Nick Roberts & Jim Few
1 CIS336 Website design, implementation and management (also Semester 2 of CIS219, CIS221 and IT226) Lecture 6 XSLT (Based on Møller and Schwartzbach,
Transforming XML Part II XML Document Transformation with XSLT John Arnett, MSc Standards Modeller Information and Statistics Division NHSScotland Tel:
Company LOGO OODB and XML Database Management Systems – Fall 2012 Matthew Moccaro.
1 XSLT An Introduction. 2 XSLT XSLT (extensible Stylesheet Language:Transformations) is a language primarily designed for transforming the structure of.
ECA 228 Internet/Intranet Design I XSLT Example. ECA 228 Internet/Intranet Design I 2 CSS Limitations cannot modify content cannot insert additional text.
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.
Transforming Documents „a how-to of transforming xml documents“ Lecture on Walter Kriha.
Lecture 11 XSL Transformations (part 1: Introduction)
Querying XML – Concluded Introduction to Views Zachary G. Ives University of Pennsylvania CIS 550 – Database & Information Systems October 9, 2003 Some.
XML Schemas, XPath, and XQuery Zachary G. Ives University of Pennsylvania CIS 550 – Database & Information Systems October 19, 2004 Some slide content.
XSLT. XSLT stands for Extensible Stylesheet Language Transformations XSLT is used to transform XML documents into other kinds of documents. XSLT can produce.
 XSL – Extensible Style Sheet Language  XSLT – XSL Transformations › Used to transform XML documents to other formats,like HTML or other XML documents.
Views and XML/Relational Mappings Zachary G. Ives University of Pennsylvania CIS 550 – Database & Information Systems October 21, 2003.
1 XMLXSL(T) and CSS NOEA/PQC (rev. fen) 2007 Stylesheets CSS:Cascading Style Sheets XSL(T):eXtended Stylesheet Language (Transformations)
© 2016 A. Haeberlen, Z. Ives CIS 455/555: Internet and Web Systems 1 University of Pennsylvania XML (continued) February 10, 2016.
Querying XML, Part II Zachary G. Ives University of Pennsylvania CIS 455 / 555 – Internet and Web Systems February 5, 2008.
Jackson, Web Technologies: A Computer Science Perspective, © 2007 Prentice-Hall, Inc. All rights reserved Chapter 7 Representing Web Data:
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.
1 XSLT XSLT (extensible stylesheet language – transforms ) is another language to process XML documents. Originally intended as a presentation language:
.
XML: Extensible Markup Language
XML Introduction Bill Jerome.
Unit 4 Representing Web Data: XML
Displaying XML Data with XSLT
Database Processing with XML
Prepared for Md. Zakir Hossain Lecturer, CSE, DUET Prepared by Miton Chandra Datta
Chapter 7 Representing Web Data: XML
Roy Tennant California Digital Library
XML, XPath, and XQuery Zachary G. Ives October 22, 2007
Views and XML Views of Relations
XML Views & Reasoning about Views
Querying XML: XPath, XQuery, and XSLT
Chapter 13 XML Yingcai Xiao.
Querying XML: XQuery and XSLT
More XML XML schema, XPATH, XSLT
Unit 6 - XML Transformations
Presentation transcript:

XML Querying and Views Zachary G. Ives November 1, 2007 University of Pennsylvania CIS 550 – Database & Information Systems November 1, 2007 Some slide content courtesy of Susan Davidson, Dan Suciu, & Raghu Ramakrishnan

Administrivia Homework 4 due 11/7 XQuery Handout re: project to come shortly – before project plan will be due Review the Shanmugasundaram paper by Wednesday 11/7 Post a 1-page summary to the newsgroup What problems did they address? Basic techniques? Strengths & weaknesses of their methods?

XQuery’s Basic Form Has an analogous form to SQL’s SELECT..FROM..WHERE..GROUP BY..ORDER BY The model: bind nodes (or node sets) to variables; operate over each legal combination of bindings; produce a set of nodes “FLWOR” statement [note case sensitivity!]: for {iterators that bind variables} let {collections} where {conditions} order by {order-conditions} (older version was “SORTBY”) return {output constructor}

“Iterations” in XQuery A series of (possibly nested) FOR statements assigning the results of XPaths to variables for $root in document(“http://my.org/my.xml”) for $sub in $root/rootElement, $sub2 in $sub/subElement, … Something like a template that pattern-matches, produces a “binding tuple” For each of these, we evaluate the WHERE and possibly output the RETURN template document() or doc() function specifies an input file as a URI Old version was “document”; now “doc” but it depends on your XQuery implementation

Example XML Data root attribute p-i element Root ?xml dblp text ?xml dblp mastersthesis article mdate mdate key key 2002… author title year school editor title journal volume year ee ee 2002… 1992 1997 ms/Brown92 The… tr/dec/… PRPL… Digital… db/labs/dec Kurt P…. Univ…. Paul R. SRC… http://www.

Two XQuery Examples <root-tag> { for $p in document(“dblp.xml”)/dblp/proceedings, $yr in $p/yr where $yr = “1999” return <proc> {$p} </proc> } </root-tag> for $i in document(“dblp.xml”)/dblp/inproceedings[author/text() = “John Smith”] return <smith-paper> <title>{ $i/title/text() }</title> <key>{ $i/@key }</key> { $i/crossref } </smith-paper>

Another Example … … root attribute p-i element Root ?xml universities text ?xml universities university … mastersthesis name country key … author title year school Univ…. USA 1999 ms/Brown92 Univ…. PRPL… Kurt P….

What If Order Doesn’t Matter? By default: SQL is unordered XQuery is ordered everywhere! But unordered queries are much faster to answer XQuery has a way of telling the query engine to avoid preserving order: unordered { for $x in (mypath) … }

Querying & Defining Metadata – Can’t Do This in SQL Can get a node’s name by querying node-name(): for $x in document(“dblp.xml”)/dblp/* return node-name($x) Can construct elements and attributes using computed names: for $x in document(“dblp.xml”)/dblp/*, $year in $x/year, $title in $x/title/text(), element node-name($x) { attribute {“year-” + $year} { $title } }

XQuery Wrap-up XQuery is very SQL-like, but in some ways cleaner and more orthogonal It is based on paths and binding tuples, with collections and trees as its first-class objects See www.w3.org/TR/xquery/ for more details on the language

XQuery Works Well with Schema, and Validates Against It (Incl. Keys) <xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema"> <xsd:complexType name=“ThesisType"> <xsd:attribute name=“key" type="xsd:string"/> … <xsd:sequence> <xsd:element name=“author" type=“xsd:string"/> ... <xsd:element name=“school" type=“xsd:string”/> </xsd:sequence> </xsd:complexType> <xsd:element name=“mastersthesis" type=“ThesisType"> <xsd:key name=“mtId">       <xsd:selector xpath=“.”/>  <xsd:field xpath="@key"/> </xsd:key> <xsd:keyref name=“schoolRef” refer=“schoolId">       <xsd:selector xpath=“./school”/>  <xsd:field xpath=“./text()"/> </xsd:keyref> </xsd:element> </xsd:schema>

A Problem We frequently want to reference data in a way that differs from the way it’s stored XML data  HTML, text, etc. Relational data  XML data Relational data  Different relational representation XML data  Different XML representation Generally, these can all be thought of as different views over the data A view is a named query Let’s start with a special presentation language for XML  HTML

XSL(T): XML  “Other Stuff” XSL (XML Stylesheet Language) is actually divided into two parts: XSL:FO: formatting for XML XSLT: a special transformation language We’ll leave XSL:FO for you to read off www.w3.org, if you’re interested XSLT is actually able to convert from XML  HTML, which is how many people do their formatting today Products like Apache Cocoon generally translate XML  HTML on the server side Your browser will do XML  HTML on the client side

A Different Style of Language XSLT is based on a series of templates that match different parts of an XML document There’s a policy for what rule or template is applied if more than one matches (it’s not what you’d think!) XSLT templates can invoke other templates XSLT templates can be nonterminating (beware!) XSLT templates are based on XPath “match”es, and we can also apply other templates (potentially to “select”ed XPaths) Within each template, we describe what should be output (Matches to text default to outputting it)

An XSLT Stylesheet <xsl:stylesheet version=“1.1”> <xsl:template match=“/dblp”> <html><head>This is DBLP</head> <body> <xsl:apply-templates /> </body> </html> </xsl:template> <xsl:template match=“inproceedings”> <h2><xsl:apply-templates select=“title” /></h2> <p><xsl:apply-templates select=“author”/></p> … </xsl:stylesheet>

Results of XSLT Stylesheet <dblp> <inproceedings> <title>Paper1</title> <author>Smith</author> </inproceedings> <author>Chakrabarti</author> <author>Gray</author> <title>Paper2</title> </dblp> <html><head>This Is DBLP</head> <body> <h2>Paper1</h2> <p>Smith</p> <h2>Paper2</h2> <p>Chakrabarti</p> <p>Gray</p> </body> </html>

What XSLT Can and Can’t Do XSLT is great at converting XML to other formats XML  diagrams in SVG; HTML; LaTeX … XSLT doesn’t do joins (well), it only works on one XML file at a time, and it’s limited in certain respects It’s not a query language, really … But it’s a very good formatting language Most web browsers (post Netscape 4.7x) support XSLT and XSL formatting objects But most real implementations use XSLT with something like Apache Cocoon – compatible with more browsers You should use XSL/XSLT to format the forms and pages for your projects – see www.w3.org/TR/xslt or the chapter we handed out for more details

Other Forms of Views XSLT is a language primarily designed from going from XML  non-XML Obviously, we can do XML  XML in XQuery … Or relations  relations … What about relations  XML and XML  relations? Let’s start with XML  XML, relations  relations

Views in SQL and XQuery A view is a named query We use the name of the view to invoke the query (treating it as if it were the relation it returns) SQL: CREATE VIEW V(A,B,C) AS SELECT A,B,C FROM R WHERE R.A = “123” XQuery: declare function V() as element(content)* { for $r in doc(“R”)/root/tree, $a in $r/a, $b in $r/b, $c in $r/c where $a = “123” return <content>{$a, $b, $c}</content> } Using the views: SELECT * FROM V, R WHERE V.B = 5 AND V.C = R.C for $v in V()/content, $r in doc(“r”)/root/tree where $v/b = $r/b return $v

What’s Useful about Views Providing security/access control We can assign users permissions on different views Can select or project so we only reveal what we want! Can be used as relations in other queries Allows the user to query things that make more sense Describe transformations from one schema (the base relations) to another (the output of the view) The basis of converting from XML to relations or vice versa This will be incredibly useful in data integration, discussed soon… Allow us to define recursive queries

Materialized vs. Virtual Views A virtual view is a named query that is actually re-computed every time – it is merged with the referencing query CREATE VIEW V(A,B,C) AS SELECT A,B,C FROM R WHERE R.A = “123” A materialized view is one that is computed once and its results are stored as a table Think of this as a cached answer These are incredibly useful! Techniques exist for using materialized views to answer other queries Materialized views are the basis of relating tables in different schemas SELECT * FROM V, R WHERE V.B = 5 AND V.C = R.C

Views Should Stay Fresh Views (sometimes called intensional relations) behave, from the perspective of a query language, exactly like base relations (extensional relations) But there’s an association that should be maintained: If tuples change in the base relation, they should change in the view (whether it’s materialized or not) If tuples change in the view, that should reflect in the base relation(s)

View Maintenance and the View Update Problem There exist algorithms to incrementally recompute a materialized view when the base relations change We can try to propagate view changes to the base relations However, there are lots of views that aren’t easily updatable: We can ensure views are updatable by enforcing certain constraints (e.g., no aggregation), but this limits the kinds of views we can have R A B 1 2 S B C 2 4 3 R⋈S A B C 1 2 4 3 delete?

Views as a Bridge between Data Models A claim we’ve made several times: “XML can’t represent anything that can’t be expressed in in the relational model” If this is true, then we must be able to represent XML in relations Store a relational view of XML (or create an XML view of relations)

A View as a Translation between XML and Relations You’ll be reviewing the most-cited paper in this area (Shanmugasundaram et al), and there are many more (Fernandez et al., …) Techniques already making it into commercial systems XPERANTO at IBM Research will appear in DB2 v9 SQL Server has some XML support; Oracle is also doing some XML … Next time you’ll see how it works!