{"id":2463,"date":"2011-05-27T15:47:58","date_gmt":"2011-05-27T20:47:58","guid":{"rendered":"http:\/\/jianmingli.com\/wp\/?p=2463"},"modified":"2011-06-01T09:55:00","modified_gmt":"2011-06-01T14:55:00","slug":"xquery","status":"publish","type":"post","link":"https:\/\/jianmingli.com\/wp\/?p=2463","title":{"rendered":"XQuery"},"content":{"rendered":"<span id=\"Overview\"><h2>Overview<\/h2><\/span>\n<p>* Used to query XML data<br \/>\n* XQuery to XML is Like SQL is to database tables<br \/>\n* Built on XPath expression<br \/>\n* Uses FLWOR (&#8220;flower&#8221;) expression: for, let, where, order by, return<br \/>\n* Is a W3C recommendation (2007)<br \/>\n* Compatible with several W3C standards<br \/>\n&#8211; XML<br \/>\n&#8211; XML Schema<br \/>\n&#8211; Namespaces<br \/>\n&#8211; XPath<br \/>\n&#8211; XSLT<\/p>\n<span id=\"Features\"><h3>Features<\/h3><\/span>\n<p>* Logical\/physical data independence<br \/>\n* Declarative<br \/>\n* High level<br \/>\n* Side-effect free<br \/>\n* Strongly typed<\/p>\n<span id=\"Pros\"><h3>Pros<\/h3><\/span>\n<p>* Easier to learn. Language more concise (less verbose).<\/p>\n<span id=\"Cons\"><h3>Cons<\/h3><\/span>\n<p>* Can not update XML documents or databases (supported in XQuery Update Facility)<br \/>\n* Lacks full text search capability (supported in XQuery Full-Text)<br \/>\n* No dynamic binding or ploymorphism<\/p>\n<span id=\"Compare_to_Others\"><h2>Compare to Others<\/h2><\/span>\n<span id=\"XQuery_1.0_vs_XPath_2.0\"><h3>XQuery 1.0 vs XPath 2.0<\/h3><\/span>\n<p>* XQuery inclues XPath 2.0 as a sublanguage<br \/>\n* Share same<br \/>\n&#8211; data model<br \/>\n&#8211; type system<br \/>\n&#8211; function libraries<\/p>\n<span id=\"XQuery_vs_XSLT_2.0\"><h3>XQuery vs XSLT 2.0<\/h3><\/span>\n<p>* Included in XSLT but missing in XQuery<br \/>\n&#8211; grouping<br \/>\n&#8211; formatting (number, date)<br \/>\n&#8211; greater control over XML namespaces<br \/>\n* XSLT itself is XML so can be manipulated by XML tools (e.g. dynamically generated)<br \/>\n*XQuery is NOT XML itself (XQuery<strong>X<\/strong> is)<\/p>\n<span id=\"Shared\"><h4>Shared<\/h4><\/span>\n<p>* Both include XPath 2.0 as a sublanguage<br \/>\n* Both share same<br \/>\n&#8211; data model<br \/>\n&#8211; type system<br \/>\n&#8211; function libraries<\/p>\n<span id=\"XQuery_Processors\"><h2>XQuery Processors<\/h2><\/span>\n<p>* <a href=\"http:\/\/www.xmlmind.com\/qizxopen\/\">Qizx\/open<\/a>. Also <a href=\"?p=2469\">this post<\/a>.<br \/>\n* <a href=\"http:\/\/saxon.sourceforge.net\/\">Saxon<\/a><br \/>\n* <a href=\"http:\/\/www.jcp.org\/en\/jsr\/detail?id=225\">XQJ (XQuery for Java)<\/a><\/p>\n<span id=\"XQuery_Functions\"><h2>XQuery Functions<\/h2><\/span>\n<span id=\"Sample_xml_doc:_books.xml\"><h3>Sample xml doc: books.xml<\/h3><\/span>\n<pre lang=\"xml\">\r\n<?xml version=\"1.0\" encoding=\"ISO-8859-1\"?>\r\n<bookstore>\r\n<book category=\"COOKING\">\r\n  <title lang=\"en\">Everyday Italian<\/title>\r\n  <author>Giada De Laurentiis<\/author>\r\n  <year>2005<\/year>\r\n  <price>30.00<\/price>\r\n<\/book>\r\n<book category=\"CHILDREN\">\r\n  <title lang=\"en\">Harry Potter<\/title>\r\n  <author>J K. Rowling<\/author>\r\n  <year>2005<\/year>\r\n  <price>29.99<\/price>\r\n<\/book>\r\n<book category=\"WEB\">\r\n  <title lang=\"en\">XQuery Kick Start<\/title>\r\n  <author>James McGovern<\/author>\r\n  <author>Per Bothner<\/author>\r\n  <author>Kurt Cagle<\/author>\r\n  <author>James Linn<\/author>\r\n  <author>Vaidyanathan Nagarajan<\/author>\r\n  <year>2003<\/year>\r\n  <price>49.99<\/price>\r\n<\/book>\r\n<book category=\"WEB\">\r\n  <title lang=\"en\">Learning XML<\/title>\r\n  <author>Erik T. Ray<\/author>\r\n  <year>2003<\/year>\r\n  <price>39.95<\/price>\r\n<\/book>\r\n<\/bookstore>\r\n<\/pre>\n<span id=\"Open_xml_file\"><h3>Open xml file<\/h3><\/span>\n<pre>\r\ndoc(\"books.xml\")\r\n<\/pre>\n<span id=\"Path_expressions\"><h3>Path expressions<\/h3><\/span>\n<pre>\r\ndoc(\"books.xml\")<strong>\/bookstore\/book\/titile<\/strong>\r\n<\/pre>\n<span id=\"Predicates\"><h3>Predicates<\/h3><\/span>\n<pre>\r\ndoc(\"books.xml\")\/bookstore\/book<strong>[price<30]<\/strong>\r\n<\/pre>\n<span id=\"FLWOR\"><h3>FLWOR<\/h3><\/span>\n<pre>\r\nfor $x in doc(\"books.xml\")\/bookstore\/book\r\nwhere $x\/price>30\r\norder by $x\/title\r\nreturn $x\/title\r\n<\/pre>\n<span id=\"References\"><h2>References<\/h2><\/span>\n<p>* <a href=\"http:\/\/www.w3.org\/TR\/xquery\/\">W3C XQuery<\/a><br \/>\n* <a href=\"http:\/\/www.w3.org\/TR\/xquery-update-10\/\">XQuery Update Facility 1.0<\/a><br \/>\n* <a href=\"http:\/\/en.wikipedia.org\/wiki\/XQuery\">Wikipedia: XQuery<\/a><br \/>\n* <a href=\"http:\/\/www.xml.com\/lpt\/a\/1549\">Comparing XSLT and XQuery By J. David Eisenberg<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Overview * Used to query XML data * XQuery to XML is Like SQL is to database tables * Built on XPath expression * Uses FLWOR (&#8220;flower&#8221;) expression: for, let, where, order by, return * Is a W3C recommendation (2007) &hellip; <a href=\"https:\/\/jianmingli.com\/wp\/?p=2463\">Continue reading <span class=\"meta-nav\">&rarr;<\/span><\/a><\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_exactmetrics_skip_tracking":false,"_exactmetrics_sitenote_active":false,"_exactmetrics_sitenote_note":"","_exactmetrics_sitenote_category":0,"jetpack_post_was_ever_published":false,"_jetpack_newsletter_access":"","_jetpack_dont_email_post_to_subs":false,"_jetpack_newsletter_tier_id":0,"_jetpack_memberships_contains_paywalled_content":false,"_jetpack_memberships_contains_paid_content":false,"footnotes":"","jetpack_publicize_message":"","jetpack_publicize_feature_enabled":true,"jetpack_social_post_already_shared":false,"jetpack_social_options":{"image_generator_settings":{"template":"highway","default_image_id":0,"font":"","enabled":false},"version":2}},"categories":[32,99],"tags":[],"class_list":["post-2463","post","type-post","status-publish","format-standard","hentry","category-xml","category-xquery"],"jetpack_publicize_connections":[],"jetpack_featured_media_url":"","jetpack_sharing_enabled":true,"jetpack_shortlink":"https:\/\/wp.me\/s8cRUO-xquery","_links":{"self":[{"href":"https:\/\/jianmingli.com\/wp\/index.php?rest_route=\/wp\/v2\/posts\/2463","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/jianmingli.com\/wp\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/jianmingli.com\/wp\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/jianmingli.com\/wp\/index.php?rest_route=\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/jianmingli.com\/wp\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=2463"}],"version-history":[{"count":12,"href":"https:\/\/jianmingli.com\/wp\/index.php?rest_route=\/wp\/v2\/posts\/2463\/revisions"}],"predecessor-version":[{"id":2502,"href":"https:\/\/jianmingli.com\/wp\/index.php?rest_route=\/wp\/v2\/posts\/2463\/revisions\/2502"}],"wp:attachment":[{"href":"https:\/\/jianmingli.com\/wp\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=2463"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/jianmingli.com\/wp\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=2463"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/jianmingli.com\/wp\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=2463"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}