XML QL query language and its implementation

zhaozj2021-02-16  51

(3) Result grouping with nested query

The above XML-QL inquiry will not group the result, the author of the same book will appear in different , if the author of the same book is placed in a . To group the results, you can use nested queries. Will change the above examples, you can get the results we want:

WHERE

$ P

in "lib.xml"

$ t </ title>,</p> <p><Publisher> <Name> Higher Education Press </ Name> </ Publisher> in $ P</p> <p>Construct <result></p> <p><title> $ t </ title></p> <p>Where <author> $ a </ author> in $ P</p> <p>Construct <Author> $ a </ author></p> <p></ result></p> <p>In the above XML-QL statement, first specify the contents of the P variable of <book> element, then determine if the content of the <book> element is included one by one contains <title> element and a <name> "Higher Education Press" <Publisher > Elements, if the conditions are met, the constructs are constructed. The result is composed of the <title> sub-element of the <book> element and a result of a nested query. The result of nested queries consists of all <author> elements in the eligible <book> element.</p> <p>If the content of the P variable has been specified, it can be used by XML-QL behind. You can also specify the P variable as the content of the <book> element by using the content_as keyword, so that the XML-QL query is simplified to:</p> <p>WHERE <book></p> <p><title> $ t </ title></p> <p><Publisher> <Name> Higher Education Press </ Name> </ Publisher></p> <p></ book> Content_as $ P in "lib.xml"</p> <p>Construct <result></p> <p><title> $ t </ title></p> <p>Where <author> $ a </ author> in $ P</p> <p>Construct <Author> $ a </ author></p> <p></ result></p> <p>Execute the above two queries, the result is the same:</p> <p><result></p> <p><Title> Database System Introduction </ Title></p> <p><author> <lastname> Sa Master </ lastname> </ author></p> <p><author> <lastname> Wang Shan </ lastname> </ author></p> <p></ result></p> <p>(4) Connecting elements according to value</p> <p>XML-QL can connect two or more elements including the same value. For example, query all <Article> elements of the author written after 2000:</p> <p>Where <article></p> <p><author></p> <p><firstname> $ f </ firstname></p> <p><lastname> $ l </ lastname></p> <p></ author> </ article> content_as $ a in "lib.xml"</p> <p><book year = $ y></p> <p><author></p> <p><firstname> $ f </ firstname></p> <p><lastname> $ l </ lastname></p> <p></ author></p> <p></ book> in "lib.xml"</p> <p>Y> 2000</p> <p>Construct <Article> $ a </></p> <p>In the above query, we used variables f and l to connect. We first specify f and l to <firstname> and <LastName> sub-elements in <author> elements, and specify the A element as the content of the <article> element. It is then judged whether there is a <book> element in <article>, its Year attribute is greater than 2000, and includes <firstname> and <lastname>, respectively, equal to F and L variable <author> element, only in this <book>, <article> element is in line with the conditions of the WHERE statement.</p> <p>In the above XML-QL, the contents of the construct statement have appeared in the WHERE statement. So, you can use the Element_as statement to avoid such repetitions.</p> <p>Where <article></p> <p><author></p> <p><firstname> $ f </ firstname></p> <p><lastname> $ l </ lastname></p> <p></ author></p> <p></ article> content_as $ a in "lib.xml"</p> <p><book year = $ y></p> <p><author></p> <p><firstname> $ f </ firstname></p> <p><lastname> $ l </ lastname></p> <p></ author></p> <p></ book> Element_as $ E in "lib.xml"</p> <p>Y> 2000</p> <p>Construct $ E</p> <p>(5) Extract data in different XML documents</p> <p>XML-QL can query multiple XML documents and combine queries. The following example is obtained from Data.xml and TaxPayers.xml two documents to obtain names (<INCOME> Elements) information, and then combine them. And these two elements are linked in <SSN> elements.</p> <p>WHERE <Person></p> <p><name> </> Element_as $ n</p> <p><SSN> $ ssn </></p> <p></> In data.xml,</p> <p><TAXPAYER></p> <p><SSN> $ ssn </></p> <p><income> </> Element_as $ I</p> <p></> In turnpayers.xml</p> <p>Construct <Result> $ N $ I </></p> <p>In addition to the above method, you can also use the skolem function to implement the above query (see) in the W3C documentation). The specific method is as follows:</p> <p>{WHERE <Person></p> <p><name> </> Element_as $ n <ssn> $ ssn </></p> <p></> In data.xml</p> <p>Construct <result ID = SSNID ($ SSN)> $ n </></p> <p>}</p> <p>{Where <TaxPayer></p> <p><SSN> $ ssn </></p> <p><income> </> Element_as $ i</p> <p></> In turnpayers.xml</p> <p>Construct <result id = SSNID ($ SSN)> $ I </></p> <p>}</p></div><div class="text-center mt-3 text-grey"> 转载请注明原文地址:https://www.9cbs.com/read-21791.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="21791" 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.040</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 = 'HiEP_2Fm9mwH9gZhrKQL7RL5QxakDVe8Qha_2Fm3hRERID32KXIbqzbp3YX7coqzjNy0MxWDtUMvrjCgutV4yGHvqA_3D_3D'; 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>