新书推介:《语义网技术体系》
作者:瞿裕忠,胡伟,程龚
   XML论坛     W3CHINA.ORG讨论区     计算机科学论坛     SOAChina论坛     Blog     开放翻译计划     新浪微博  
 
  • 首页
  • 登录
  • 注册
  • 软件下载
  • 资料下载
  • 核心成员
  • 帮助
  •   Add to Google

    >> 本版讨论XLink, XPointer, XQuery
    [返回] 中文XML论坛 - 专业的XML技术讨论区XML.ORG.CN讨论区 - XML技术『 XQuery/XLink/XPointer/ 』 → 我的第一帖,写一些总结的内容 查看新帖用户列表

      发表一个新主题  发表一个新投票  回复主题  (订阅本版) 您是本帖的第 9189 个阅读者浏览上一篇主题  刷新本主题   树形显示贴子 浏览下一篇主题
     * 贴子主题: 我的第一帖,写一些总结的内容 举报  打印  推荐  IE收藏夹 
       本主题类别:     
     杨一 帅哥哟,离线,有人找我吗?水瓶座1983-2-19
      
      
      等级:大一(猛啃高等数学)
      文章:11
      积分:135
      门派:XML.ORG.CN
      注册:2005/11/16

    姓名:(无权查看)
    城市:(无权查看)
    院校:(无权查看)
    给杨一发送一个短消息 把杨一加入好友 查看杨一的个人资料 搜索杨一在『 XQuery/XLink/XPointer/ 』的所有贴子 引用回复这个贴子 回复这个贴子 查看杨一的博客楼主
    发贴心情 我的第一帖,写一些总结的内容

    XQuery是一种新兴的,正在发展之中的规范。可以认为是"XML Query",是W3C为使用简单和统一的语法来访问分布式的信息存储系统例如内容仓库,文件,关系型数据库,和对象仓库而制订的XML标准。XQuery使用XML结构的优势能表达跨越多种类型数据查询的能力.XQuery对以任何形式存在的XML进行查询。
    XQuery提供了对于任何形式的数据的转换,与关系型数据库的衔接。通过他的衔接,就可以把关系型的数据库作为一种XML的形式来查询,并解析,包括输出。
    XQuery不仅局限为服务端的使用,已经有成型的技术和产品在客户端的功能中应用了这种技术XQuery已经有一些大公司提供了相应的成型的产品(在下面的内容中进行讨论),并且这些产品所遵循的规范并不相同,这是需要注意的地方。
    XQuery是构建于XPath之上的,XPath能够迅速的提取XML的某一具体部分,比如元素,属性等等,它可以是一个集合,也可以是一个元素。在现有的解析XML的DOM Level3实现中(开源),DOM4J很好的支持了XPath,在DOM4J的官方网站上可以找到一个quick guide,里面有介绍XPath内容的部分。


    Dom4J的官方网站是:
    http://www.dom4j.org/guide

    XPath的中文实例说明:
    http://www.zvon.org/xxl/XPathTutorial/General/examples.html

    下面是一些XPath应用的例子:
    /html/body/h1. Selects all <h1> elements that are children of a <body> element that is the child of an <html> element that is the root element in a document. The result may be multiple <h1> elements.
    //h1. Selects all <h1> elements that appear anywhere within a document. The double-slash indicates arbitrary depth.
    count(//book). Returns the number of <book> elements that appear within a document.
    //book[author = "Hunter"]. Returns all <book> elements that have an <author> child element whose string value is "Hunter." The square brackets surround a "predicate" that acts as a filter on the match results.
    //book[@year > 1999]. Returns all <book> elements that have an attribute "year with a value greater than 1999." The @ sign marks year as an attribute. Notice how an attribute value can be treated as an integer for comparison within XPath.
    //book[@pages]. Returns all <book> elements that have a pages attribute with any value.
    //book/@pages. Returns all the pages attributes that are attached to <book> elements.
    (i | b). Returns all <i> or <b> child elements from the current context node. XPath expressions work like file system lookups; if there's no leading slash, the path is relative to the "current context node" (specified outside the expression).
    (//servlet | //servlet-mapping) [servlet-name = $servlet]. Returns all <servlet> or <servlet-mapping> elements that have a <servlet-name> child element whose value equals the $servlet variable.
    //key[. = "Total Time"]. Returns all <key> elements that have a value of "Total Time." The "." in the expression represents the context node, which is similar to a "this" pointer in object-oriented languages.
    (//key)[1]/text(). Returns the text nodes of the first <key> element within the document.

    在XQuery中,XPath只能用于简单的查询, 尽管它们通常也作为复杂查询的一部分而存在. 同志们可以在前面提到的XPath网站上找到相关的用XPath查询的例子。


    FLWOR Expressions (这个名字是不是听上去怪怪的?没错,它的读音是flower)


    它的名称的由来如下:
    For, Let, Where, Order by, Return
    For提供了遍历的方法,Let提供了赋值的方法
    http://www.w3.org/ XML/Query提供了一个应用这些命令查询的例子:
    <books-with-prices>
    {
    for $b in document("http://www.bn.com/bib.xml")//book,
    $a in document("http://www.amazon.com/reviews.xml")//entry

    where $b/title = $a/title
    return
    <book-with-prices>
    { $b/title }
    <price-amazon>{ $a/price/text() }</price-amazon>
    <price-bn>{ $b/price/text() }</price-bn>

    </book-with-prices>
    }
    </books-with-prices>

    Executing this query returns a result like this:

    <books-with-prices>

    <book-with-prices>
    <title>TCP/IP Illustrated</title>
    <price-amazon>65.95</price-amazon>
    <price-bn>65.95</price-bn>
    </book-with-prices>
    <book-with-prices>
    <title>Advanced Programming in the Unix environment</title>
    <price-amazon>65.95</price-amazon>

    <price-bn>65.95</price-bn>
    </book-with-prices>
    <book-with-prices>
    <title>Data on the Web</title>
    <price-amazon>34.95</price-amazon>
    <price-bn>39.95</price-bn>
    </book-with-prices>
    </books-with-prices>


    可以看到这种查询语句和SQL十分相似,区别就是数据的来源和去向都只是XML。
    下面是加入了条件得查询:


    for $b in document("books.xml")/bib/book
    return
    if (count($b/author) <= 2) then $b
    else <book> { $b/@*, $b/title, $b/author[position() <= 2], <et-al/>,
    $b/publisher, $b/price } </book>

    XQuery支持很多的操作符和函数,你也可以定制自己的函数。

    在网站:

    http://www.w3.org/XML/Query/

    可以找到更多的关于XQuery的资料

    在网址:

    http://www.w3.org/XML/Query#implementations

    提供了大量XQuery提供商的相关资料

    各个提供商的链接

    一些XQuery的好的实现:

    Mark Logic's Content Interaction Server

    Combines a search engine with a database to produce a content database. Scales past a Terabyte. For learning, you can get a free, non-expiring Community Licensed version.

    BEA's Liquid Data

    Lets you write a single query to access data from Web services, relational databases, flat files, XML files, applications, and Web sites. Time-limited evaluation license.

    Ipedo's XML Intelligence Platform

    Provides access to XML and relational data sources for Enterprise Information Integration. Time-limited evaluation license.

    X-Hive

    A native XML database. Includes an online demo. Time-limited evaluation license.

    Other interesting XQuery implementations.

    Qizx/open

    A Java-based, open source XQuery engine.

    IPSI-XQ

    A self-described "prototype" engine. Free for non-commercial use.

    Qexo

    Open source under a license similar to the GPL, managed by Per Bothner.

    Saxon

    Open source from Michael Kay, with a commercial variety from Saxonica Limited.


    同时,在xquery网站上提供了一个BumbleBee供下载,它可以测试各种xquery引擎的性能。

    http://www.xquery.com/bumblebee/download.html


    参考文章:
    http://www.oracle.com/technology/oramag/oracle/03-may/o33devxml.html

    http://publishblog.blogchina.com/blog/tb.b?diaryID=1169160

    http://www.yesky.com/429/1952429.shtml


       收藏   分享  
    顶(0)
      




    点击查看用户来源及管理<br>发贴IP:*.*.*.* 2005/11/16 11:15:00
     
     GoogleAdSense水瓶座1983-2-19
      
      
      等级:大一新生
      文章:1
      积分:50
      门派:无门无派
      院校:未填写
      注册:2007-01-01
    给Google AdSense发送一个短消息 把Google AdSense加入好友 查看Google AdSense的个人资料 搜索Google AdSense在『 XQuery/XLink/XPointer/ 』的所有贴子 访问Google AdSense的主页 引用回复这个贴子 回复这个贴子 查看Google AdSense的博客广告
    2024/4/28 16:17:54

    本主题贴数1,分页: [1]

    管理选项修改tag | 锁定 | 解锁 | 提升 | 删除 | 移动 | 固顶 | 总固顶 | 奖励 | 惩罚 | 发布公告
    W3C Contributing Supporter! W 3 C h i n a ( since 2003 ) 旗 下 站 点
    苏ICP备05006046号《全国人大常委会关于维护互联网安全的决定》《计算机信息网络国际联网安全保护管理办法》
    62.500ms