XQuery query language and application instance analysis

zhaozj2021-02-16  86

XQuery query language and application instance analysis

content:

Introduction First, XQuery Overview Second, XQuery and Its Application Example III, Comparison of Query Language, Summary Reference Information About The Author's Evaluation

(Transferred from IBM DW)

July 2004

This article describes the main features of the XQuery query language and discusses the application of xQuery language in data query, conversion.

Introduction XML has become a standard in fact data representation and data exchange. Start, core features such as self-description and specific scalability provide the flexibility required for messaging between different applications. Especially with the vigorous development of Web Service in recent years, XML is increasingly active in data exchange and storage, and the semi-structural data expressed by XML is increasingly common, especially in the B2B e-commerce industry. In the face of an exponential growth of XML data, it is inevitable to require more efficient data management capabilities and faster and more accurate queries. Therefore, how to accurately query the information required from the XML data source, it will become more and more important. I. XQuery Overview The XQuery Working Group was formally established in September 1999. It was a flexible query language to extract data from the XML document. The latest XQuery draft announced by W3C is the version of November 12, 2003, which is still in constant revision and perfect [1]. As a new type of query language, XQuery draws the advantages of several other query languages, suitable for queries of various types of XML data sources, not only querying power, but also simple and flexible and easy to implement. Moreover, XQuery also has the characteristics of retrieving information from a variety of databases, which can query various data and documents. XQuery is built on the XPath specification, which is capable of selecting a special node sequence from the document via the XPath expression. XQuery is a functional language that represents a query as an expression. Through a variety of expressions it support, it can have a variety of different forms. Various XQuery expressions can be completely nested, also support sub-queries. At present, the three mainstream manufacturers of the database industry Oracle, IBM, and Microsoft have provided support for the XQuery specification in their respective products. Second, XQuery and its application example 1. Query Application XQuery has a powerful query and retrieval function, which completes queries by various expressions, symbols, operands, and its expressive operation objects can be another expression. As a function language, it also allows various expressions to nested each other. At the same time, it is also a strict language that requires strict data. The operand, operators, and functions in the expression must be specified [2]. First, look at an example of XML document BIB.xml that states book information.

China-pub Java programming idea </ title> <publicisher> Machinery Industry Press </ Publisher> <Year> 2002 </ year> <author> <firstname> Bruce </ firstname> <lastname> Eckel </ lastname> </ author> <price> 99 </ price> <book> <book> <title> xml manual </ title> <publiciisher> Electronic Industry Press </ Publisher> <year> 2003 </ year> <author> <firstname> charles f. </ Firstname> <lastname> Goldfarb </ lastname> </ author> <price> 69 </ price> < / book> </ vendor> ... </ bib> 1. 1 XPath XPath is a language that can find location information in an XML document that extracts a single project or a set of items from an XML file. XPath is similar to the file path we used in your computer system, just like the C: / Winnt we are well known. By XPath path expression, you can easily locate data in an XML document to determine nodes. For example, this basic type of XPath expression (corresponding to the XML document above): / bib / vendor / @ ID. This expression starts from the document root, selects all BIB sub-elements, then select all the Vendor child elements of the BIB, and finally select all ID attributes of the Vendor child element. Of course, the ability to XPath expressions is far exceeded by this simple statement. Using XPath quickly locates and extracts information in the XML hierarchy, and its built-in function provides a comprehensive function that can be easily handled value and text data. The following is a typical XPath path expression: (with "/" to start representing an absolute path of the element)</p> <p>Path Expression Select XML Document section / Select the root node of the XML document / * Select all child nodes of the root node, * Match all BIB elements of the node / bib to select the root node // Book Select root node Book Elements in All Backhills Nods @ ID Select sub-node / BIB / BOOK [2] containing ID attributes Select BIB's second child // vendor [@ id = 'id1_2'] / book selection compliance with "Properties ID All BOOK Elements of 'Id1_2' "/ BIB / VENDOR / BOOK [Year> 2002] Select all BOOK elements that meet" Element Year> '2002' ", of course, XPath can also achieve many other features, please see W3C XPath specification [3]. 1. 2 FLWR Expression XQuery is the FLWR expression (pronounced Flower), which is a typical expression that can complete a query with some actual meaning. FLWR expressions include pattern matching, filter selection, and results constructing these three operations. The FLWR statement is the closer SQL statement with XQuery. Using the FLWR statement, you can create a specific query with more natural methods than XPath 1.0 statements. [5] The FLWR expression is made up of the clause defined by for-let-where-return, updated to FLWOR, O represents the newly joined Order By clause in the latest standard. FLWOR expression represents the first letters of For-let-where-order by- return. The resulting FLWOR expression can complete a lot of tasks that are difficult to complete in XSLT. It supports iteration and can bind variables to intermediate results. This expression is very useful when connecting and reconstructing data for two or more documents. Each FLWOR expression has one or more For clauses, one or more LET clauses, an optional WHERE clause, an ORDER BY clause, and a return clause. The FOR clause binds the node to the variable to continue to go to each node in the cycle sequence; the Let clause is a variable to assign a value or a sequence; the return clause defines the content to return each tuple; The WHERE clause is true if its valid Boolean value is true, then the group is reserved, and its variable binding is used in the return clause, and if its valid Boolean value is false, the group is discarded. Here is a simple example: for $ i in document ("bib.xml") / BIB / VENDOR / BOOKWHER $ I / Price> 80 Return <highpricedbook> {$ I / TITLE, $ I / Price} </ highpricedbook> this example It is not available to the let statement, it is only optional. It should be noted that the variables are started with symbol $, which are bound to different node sequences and then passed through the statement. The flower bracket {} represents the output information and the information to be evaluated. It can be seen that the FLWOR expression is a type type with a variety of changes that generate a large number of different query instances. The "return" keyword behind the object itself can be replaced by another FLWOR expression, which can constantly connect the FLWOR expression, so that XQuery has a very rich expression. Its query results are:</p> <p><Highpricedbook> <title> java </ title> <price> 99 </ price> </ highpricedbook> 1.3 Other features except for the path expression and FLWR expressions, XQuery has 5 basic expression modes: Elemental constructor, operator and function expression, conditional expression, defined expression, list constructor, data type expression [4]. By a variety of combinations, a query statement with rich and powerful query search function can be generated. Below is an example of an arithmetic operator ' ': Let $ A: = Document ("BIB.XML") / BIB / VENDOR / BOOK [1] / PriceLet $ B: = Document ("BIB.XML") / BIB / VENDOR / BOOK [2] / priceReteURN <total_price_of_books> {$ A $ B} </ TOTAL_PRICE_OF_BOOKS> Query results are as follows:</p> <p><total_price_of_books> 168 </ total_price_of_books> In the query statement, you can also use if ... then ... else ... such a selection structure, such as the following example:</p> <p>For $ i in document ("bib.xml") / BIB / VENDOR / BOOKRETURNIF ($ I / Price <70) Then <lowpricedbook> {$ I / TITLE, $ I / Price} </ lowpricedbook> else <highpricedbook> { $ I / TITLE, $ I / Price} </ highpricedbook> The result of the query is as follows:</p> <p><Highpricedbook> <title> java </ title></p> <p><Price> 99 </ price> </ highpricedbook> <lowpricedbook> <title> XML Handbook </ title> <price> 69 </ price> </ lowpricedbook> 2. Conversion Applications When using integration, a variety of vocabulary can be used, and if these applications are interactive, including data exchange, it is necessary to convert XML documents for different phrases. At this time, XQuery can adapt the demand because it has a lot of functions such as XSLT to convert data from potential heterogeneous data sources. Let's take a look at an example of using XQuery to implement document conversion, which converts the properties of the XML document to an element display. This is an original XML document as an input, which describes the order item.</p> <p><ORDER ID = "1000001"></p> <p><ITEM ID = "111" Qty = "10" /> <item ID = "123" Qty = "28" /> <item ID = "135" Qty = "16" /> </ order> The following is implementing conversion The XQuery statement used by the function. It is just simply changing the structure of the original document, plus some elements.</p> <p>Let $ ORDER: = Document ("Order.xml") / OrderReturn <PurchaseOrder> <Order> {$ ORDER / @ id} </ order> <lineItems> {for $ Item in $ Order / itemreturn <item> <id> {String ("> $ item / @ id)} </ id> <qty> {string ($ item / @ qty)} </ qty> </ item>} </ lineItems> </ purchaseorder> As shown below: <PurchaseOrder></p> <p><ORDER ID = "1000001" /> <lineItems> <item> <id> 111 </ id> <qty> 10 </ qty> </ item> <item> <id> 123 </ id> <qty> 28 </ Qty> </ item> <item> <id> 135 </ id> <qty> 46 </ qty> </ item> </ lineitems> </ purchaseorder> in this case, when using XML data An application uses different vocabulary to simplify the problem. When they use different DTD (Schema), this is likely to happen, and because of different applications, it will be used in an XML. The DTD (Schema) is designed to freely select element or attribute when some feature. This involves the conversion of the document. Of course, in the actual demand, the conversion between the vocabulary is probably more complicated than this example, but from this example we can see that the powerful conversion function of XQuery is enough to express most of this requirement. Because XQuery has a very flexible construction of the results tree mechanism, it has considered the structural conversion when designing, so in some cases it makes a conversion work than the XSLT is more concise. 3. Update Applications Although the latest XQuery 1.0 standard also does not support update operations, this research is developing very quickly, and some Native XML database products such as Tamino, Ipedo has been updated in their respective products. Moreover, another organization XML: DB also proposes a draft xupdate language. Obviously, XQuery is not perfect in this regard than the SQL / XML can be easily updated. This is also the most obvious gap between XQuery and SQL / XML. The syntax for updating the elements in the XML document has not been defined in XQuery. The update mechanism for SQL / XML has been defined and has been applied to Oracle and DB2. Third, the comparison of query language From the previous example, especially the FLWR structure, we can see that XQuery has the appearance and ability of SQL, which is welcome to the user who is familiar with the relational database. So what is new for SQL standards in the database industry for XML query requirements. We may wish to compare SQL / XML and XQuery with XML query language standards. As part of the latest SQL: 2003 standards raised in December 2003, SQL / XML is based on the extension of relational query language, and has especially added support for XML. Although SQL / XML and XQuery are XML query criteria, they are based on completely different models, SQL / XML is more suitable for relational models, which can provide full access in existing SQL environments, including xQuery1.0 standards are not prepared Provided features such as updates and full text queries. In addition, the advantage of SQL / XML is that database vendors have accumulated many years of experience in SQL's query optimization. It can be said that SQL / XML provides functions that can support relational data in existing SQL environments while creating XMLs from relational data. For queries, SQL / XML, and XQuery reach similar effects only based on relational data. However, their implementation mechanisms for the same function may be completely different, because SQL / XML operation is between SQL and XML, and XQuery is based on pure XML, it is from XML-centered angle. Expected questions. XQuery is best at handling the "mix" document, which contains documents that describe the flow and quantization data.</p> <p>Therefore, XQuery shows more important advantages for queries across relational databases and other XML data sources. It seems that they are complementary. SQL / XML and XQuery standards are hoped to join the other part of the other party in the standard. However, from a long time, developers may wish to keep XML abstractions on all of their data sources. In this case, as a rich and comprehensive programming language developed for processing complex data, XQuery may become an important standard. IV. Summary now, the XQuery standard is still growing and perfect, in general, XQuery is the best choice for XML programmers who need to process XML data or need to process XML and relational data, but It is equally insufficient, and relatively mature SQL, its technical support and experience should be less. We can affirm that whether SQL / XML or XQuery will play an important role in XML queries, and XQuery will become an important standard in general XML processing. Reference http://www.w3.org/xml/query http://www.w3.org/tr/xquery http://www.w3.org/tr/xpath xQuery: a guided tour http: // Www.datadirect.com/news/whatsnew/xqurybook/index.ssp ​​2003.9</p></div><div class="text-center mt-3 text-grey"> 转载请注明原文地址:https://www.9cbs.com/read-13029.html</div><div class="plugin d-flex justify-content-center mt-3"></div><hr><div class="row"><div class="col-lg-12 text-muted mt-2"><i class="icon-tags mr-2"></i><span class="badge border border-secondary mr-2"><h2 class="h6 mb-0 small"><a class="text-secondary" href="tag-2.html">9cbs</a></h2></span></div></div></div></div><div class="card card-postlist border-white shadow"><div class="card-body"><div class="card-title"><div class="d-flex justify-content-between"><div><b>New Post</b>(<span class="posts">0</span>) </div><div></div></div></div><ul class="postlist list-unstyled"> </ul></div></div><div class="d-none threadlist"><input type="checkbox" name="modtid" value="13029" checked /></div></div></div></div></div><footer class="text-muted small bg-dark py-4 mt-3" id="footer"><div class="container"><div class="row"><div class="col">CopyRight © 2020 All Rights Reserved </div><div class="col text-right">Processed: <b>0.052</b>, SQL: <b>9</b></div></div></div></footer><script src="./lang/en-us/lang.js?2.2.0"></script><script src="view/js/jquery.min.js?2.2.0"></script><script src="view/js/popper.min.js?2.2.0"></script><script src="view/js/bootstrap.min.js?2.2.0"></script><script src="view/js/xiuno.js?2.2.0"></script><script src="view/js/bootstrap-plugin.js?2.2.0"></script><script src="view/js/async.min.js?2.2.0"></script><script src="view/js/form.js?2.2.0"></script><script> var debug = DEBUG = 0; var url_rewrite_on = 1; var url_path = './'; var forumarr = {"1":"Tech"}; var fid = 1; var uid = 0; var gid = 0; xn.options.water_image_url = 'view/img/water-small.png'; </script><script src="view/js/wellcms.js?2.2.0"></script><a class="scroll-to-top rounded" href="javascript:void(0);"><i class="icon-angle-up"></i></a><a class="scroll-to-bottom rounded" href="javascript:void(0);" style="display: inline;"><i class="icon-angle-down"></i></a></body></html><script> var forum_url = 'list-1.html'; var safe_token = 'mdb95trTxRXJEfkVPfveUxBYgOj6ptaUuO3Rzl58N45JeRhQDoiTPsDvKaZZ6aD4LwgezSduI_2B0PDuwX'; var body = $('body'); body.on('submit', '#form', function() { var jthis = $(this); var jsubmit = jthis.find('#submit'); jthis.reset(); jsubmit.button('loading'); var postdata = jthis.serializeObject(); $.xpost(jthis.attr('action'), postdata, function(code, message) { if(code == 0) { location.reload(); } else { $.alert(message); jsubmit.button('reset'); } }); return false; }); function resize_image() { var jmessagelist = $('div.message'); var first_width = jmessagelist.width(); jmessagelist.each(function() { var jdiv = $(this); var maxwidth = jdiv.attr('isfirst') ? first_width : jdiv.width(); var jmessage_width = Math.min(jdiv.width(), maxwidth); jdiv.find('img, embed, iframe, video').each(function() { var jimg = $(this); var img_width = this.org_width; var img_height = this.org_height; if(!img_width) { var img_width = jimg.attr('width'); var img_height = jimg.attr('height'); this.org_width = img_width; this.org_height = img_height; } if(img_width > jmessage_width) { if(this.tagName == 'IMG') { jimg.width(jmessage_width); jimg.css('height', 'auto'); jimg.css('cursor', 'pointer'); jimg.on('click', function() { }); } else { jimg.width(jmessage_width); var height = (img_height / img_width) * jimg.width(); jimg.height(height); } } }); }); } function resize_table() { $('div.message').each(function() { var jdiv = $(this); jdiv.find('table').addClass('table').wrap('<div class="table-responsive"></div>'); }); } $(function() { resize_image(); resize_table(); $(window).on('resize', resize_image); }); var jmessage = $('#message'); jmessage.on('focus', function() {if(jmessage.t) { clearTimeout(jmessage.t); jmessage.t = null; } jmessage.css('height', '6rem'); }); jmessage.on('blur', function() {jmessage.t = setTimeout(function() { jmessage.css('height', '2.5rem');}, 1000); }); $('#nav li[data-active="fid-1"]').addClass('active'); </script>