140 likes | 261 Views
XML Query Language. Changki Kim July 14 2005 MSE. Contents. Introduction XQuery Data Model XQuery Expression Types Implementations of XQuery XQuery API for Java Conclusion. Introduction. XML (Extensible Markup language)
E N D
XML Query Language Changki Kim July 14 2005 MSE
Contents • Introduction • XQuery Data Model • XQuery Expression Types • Implementations of XQuery • XQuery API for Java • Conclusion
Introduction • XML (Extensible Markup language) • the format of choice for the exchange of information among various applications on the Internet • Its flexibility for representing many different kinds of information (multimedia presentation, database tables, web pages) • World Wide Web Consortium(W3C) • A series of standard : XML Schma, XPath,XSLT, and XQuery • XQuery • A requirement for a query language against data in XML data format. • Early Attempts to define a query language for XML data(XQL,XML-QL, Quilt) • In October 1999, W3C convened the XML QUery Working Group • XQuery 1.0:An XML Query Language.(2002)
Introduction • SQL & XQuery • XQuery goes beyond the functionality of relational query language • It is often thought of as a native XML programming language • Only XML data is complex, the operations for processing XML are simple. • XQuery can easily search any XML structure with predefined expressions. • Even when the data is not physically stored as XML, XQuery can be used with middleware that provides an XML view of the data. XQUery is widely used for data integration!!!!!
XQuery Data Model • The input and output is defined in terms of the XQuery1.0 and XPath2.0 data model • The data model is based on the notion of a sequence. (sequence>item>node or atomic value) • The output sequence may be heterogeneous. However the result of the operation is single-level sequence of nodes and atomic values.
XQuery Expression Types • There are 7 types of expressions in XQuery • Path expressions. • Element constructors. • FLWR expression, • Expressions involving operators and functions • Conditional expression. • Quantified expression. • The expressions can be used together both sequentially and nested • Path expression • It is used to locate nodes in XML data. • It consists of a series of one or more steps, separated by slash ,/, or double slash , // • Example : document(“books.xml”)//book, document(“books.xml”)/bib/book/author[last=“Stevens”]
XQuery Expression Types • Element constructors • It is used when a query needs to create new elements. • Example : date(“2005-5-31”) • FLWR expressions • It is the analogue of the SELECT FROM-WHERE construction in SQL. • Example : for $b in document(“books.xml”)//book where $b/@year = “2000” return $$b/title • Expressions involving operators and functions • Built-in function (AVG,SUM,COUNT,DOCUMENT,EMPTY) • Conditional expressions • IF-THEN-ELSE • Quantified expressions • SOME(existential) and EVERY(universial)
Implementation of XQuery • Currently several implementations of XQuery are available. • References to Xquery Implementations. • X-Hive: http://www.x-hive.com/xquery/ • Fatdog: http://www.fatdog.com • Kawa-XQuery: http://www.gnu.org/software/kawa/xquery/ • Kweelt: http://db.cis.upenn.edu/Kweelt/ • Lucent: http://db.bell-labs.com/galax/ • Microsoft: http://131.107.228.20 • Openlink Software: http://demo.openlinksw.com:8391/xquery/demo.vsp • QuiP (Software AG): http://www.softwareag.com/developer/quip/default.htm • XQuench: http://sourceforge.net/projects/xquench/ • The goal of implementation is to investigate implementability and usability of XQuery and to provide feedback to the W3C XML Query Working Group.
Implementation of XQuery • X-Hive (active member of W3C) • This company provides on-line XQuery demo. • The Query I wrote on the browser is running on top X-Hive/DB • The result is returned in less than 5 seconds
XQuery API for Java(XQJ) • XQJ is an API designed to support the XQuery language, just like the JDBC API supports the SQL query language. • The XQJ standard (JSR 225) is being developed under the Java Community Process. • For more information, http://www.jcp.org/en/jsr/detail?id=225. • DataDirect XQuery is a Java implementation of XQuery that uses the XQuery API for Java (XQJ) for accessing both XML and relational sources.
XQuery API for Java(XQJ) • XQJ sample Java code to execute an XQuery query //import the XQJ classes import com.ddtek.xquery.alpha.*; import com.ddtek.xquery.xqj.mediator.DDXQDataSource; // establish a connection to a DataDirect XQuery data source DDXQDataSource ds = new DDXQDataSource( ); ds.setConfigFile("stockconfigfile.xml"); XQConnetion conn = ds.getConnection("myuserid", "mypswd"); // create an expression object that is used to execute // an XQuery query XQExpression expr = conn.createExpression(); // the XQuery query String es = "for $h in collection('HOLDINGS')/Holdings“ + "where ($h/STOCKTICKER='AMZN'“ + "return $h"; // execute the XQuery query XQResultSequence result = expr.executeQuery(es); System.out.println(result.getSequenceAsString()); // free all resources result.close(); expr.close(); conn.close();
Shortcomings • XQuery is still in the W3C Working Draft stage. • Update query (including insert query) is not specified in the current XQuery 1.0 drafts. • It does not contain full text search facilities ”Find all elements containing a particular word” . • It has backward compatibility with XPath1.0 • There are other minor issues( inconsistencies with and between the working drafts)
Conclusion • XQuery is a very promising initiative in defining the standard for query and retrieval of XML. • It is a functional language consisting of several types of expressions. • It is defined in terms of a data model based on heterogeneous sequences of nodes and atomic values. • Currently, Design of the XQuery is an ongoing activity of the W3C XML Query Working Group. • XQuery will help XML to realize its potential as a universal in formation representation.
Reference • Useful web site. • http://www.w3.org/TR/xquery/ • http://hake.stanford.edu/~widom/cs145/. • http://www.perfectxml.com/articles/xml/xquery.asp • http://www.ipedo.com/html/xquery/xquery_tutorial/ • http://www.datadirect.com/products/xquery/xquerybetahome/index.ssp (XQJ) • Paper • D.Chamberlin.”Xquery: An XML Query Language,” IBM System Journal, Vol 41, No 4, 2002