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

    >> 本版讨论XLink, XPointer, XQuery
    [返回] 中文XML论坛 - 专业的XML技术讨论区XML.ORG.CN讨论区 - XML技术『 XQuery/XLink/XPointer/ 』 → XQuery从头学 查看新帖用户列表

      发表一个新主题  发表一个新投票  回复主题  (订阅本版) 您是本帖的第 178964 个阅读者浏览上一篇主题  刷新本主题   平板显示贴子 浏览下一篇主题
     * 贴子主题: XQuery从头学 举报  打印  推荐  IE收藏夹 
       本主题类别:     
     xml-linguist 帅哥哟,离线,有人找我吗?
      
      
      等级:大三暑假(参加全国数模竞赛拿了一等奖)
      文章:121
      积分:869
      门派:XML.ORG.CN
      注册:2007/3/28

    姓名:(无权查看)
    城市:(无权查看)
    院校:(无权查看)
    给xml-linguist发送一个短消息 把xml-linguist加入好友 查看xml-linguist的个人资料 搜索xml-linguist在『 XQuery/XLink/XPointer/ 』的所有贴子 引用回复这个贴子 回复这个贴子 查看xml-linguist的博客楼主
    发贴心情 XQuery从头学

    Let's try to learn some basic XQuery syntax by looking at an example.
    从实例直接开始。

    We will use the following XML document in the examples below.
    先看下面的XML文件

    "books.xml":

    <?xml version="1.0" encoding="ISO-8859-1"?>
    <bookstore>
    <book category="COOKING">
      <title lang="en">Everyday Italian</title>
      <author>Giada De Laurentiis</author>
      <year>2005</year>
      <price>30.00</price>
    </book>
    <book category="CHILDREN">
      <title lang="en">Harry Potter</title>
      <author>J K. Rowling</author>
      <year>2005</year>
      <price>29.99</price>
    </book>
    <book category="WEB">
      <title lang="en">XQuery Kick Start</title>
      <author>James McGovern</author>
      <author>Per Bothner</author>
      <author>Kurt Cagle</author>
      <author>James Linn</author>
      <author>Vaidyanathan Nagarajan</author>
      <year>2003</year>
      <price>49.99</price>
    </book>
    <book category="WEB">
      <title lang="en">Learning XML</title>
      <author>Erik T. Ray</author>
      <year>2003</year>
      <price>39.95</price>
    </book>
    </bookstore>
    --------------------------------------------------------------------------------

    How to Select Nodes From "books.xml"?
    从"books.xml"中选取结点

    Functions
    XQuery uses functions to extract data from XML documents.
    XQuery利用函数从XML文件中提取数据。(注:本人非理科、非工科、非IT行业,我一看见Functions就会想到“功能”。今天学一个行话,“函数”,不知合适不合适。)

    The doc() function is used to open the "books.xml" file:
    用doc() 来打开"books.xml"文档:
    doc("books.xml")

    Path Expressions
    XQuery uses path expressions to navigate through elements in an XML document.
    XQuery采用路径表达式在XML文件的元素中导航。

    The following path expression is used to select all the title elements in the "books.xml" file:
    用以下路径表达式在 "books.xml"文档中选取所有的"title"元素:
    doc("books.xml")/bookstore/book/title

    (/bookstore selects the bookstore element, /book selects all the book elements under the bookstore element, and /title selects all the title elements under each book element)
    (/bookstore选取"bookstore"元素;/book选取"bookstore"元素下属的所有"book"元素;/title选取每个"bookstore"元素下属的所有"title"元素)

    The XQuery above will extract the following:
    以上XQuery提取以下数据:

    <title lang="en">Everyday Italian</title>
    <title lang="en">Harry Potter</title>
    <title lang="en">XQuery Kick Start</title>
    <title lang="en">Learning XML</title>

    Predicates
    XQuery uses predicates to limit the extracted data from XML documents.
    谓词
    XQuery利用谓词来限定从XML文件中提取的数据。

    The following predicate is used to select all the book elements under the bookstore element that have a price element with a value that is less than 30:
    以下谓词用以选取"bookstore"元素下属的、拥有"price"元素且"price"元素值小于30的所有"book"元素:
    doc("books.xml")/bookstore/book[price<30]

    The XQuery above will extract the following:
    上述XQuery提取以下数据:

    <book category="CHILDREN">
      <title lang="en">Harry Potter</title>
      <author>J K. Rowling</author>
      <year>2005</year>
      <price>29.99</price>
    </book>

    [此贴子已经被作者于2007-4-14 18:18:20编辑过]

       收藏   分享  
    顶(0)
      




    ----------------------------------------------
    有些事,我只需要知道是否可以做,我不一定非得学会怎么做。

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

    本主题贴数32,分页: [1] [2] [3] [4]

     *树形目录 (最近20个回帖) 顶端 
    主题:  XQuery从头学(3172字) - xml-linguist,2007年4月12日
        回复:  完全跟w3cshool上面的内容一样,没有任何创新啊!所用的论坛也不具有交互性,哎,论坛可以..(96字) - yhjhoo,2009年2月12日
        回复:  请问楼主,xquery代码究竟该放在什么地方。可以直接嵌入html吗?我试过,好像不行。有谁用过x..(116字) - venee_lee,2008年10月8日
        回复:  其实,我根本不懂XQuery是干什么的。在我做资料的过程中,有些构思很难一步到位:任何一个方案都..(411字) - xml-linguist,2008年7月28日
        回复:  太好了~~楼主加油~!(21字) - kevin86713,2008年1月15日
            回复:  试出来了,把xquery放在后缀为xq的文件中就可以了。我用的是altova XMLspy。感觉还..(89字) - venee_lee,2008年10月9日
        回复:  一个问题我不知道怎么执行xquery。。。比较郁闷表达式基本上可以看懂我用xmlbean..(114字) - viva156,2007年12月19日
        回复:  xquery应该写在哪?(94字) - feathen1983,2007年10月16日
        回复:  很好,谢谢(10字) - 龙藤,2007年10月16日
        回复:  请继续。(8字) - jx,2007年9月23日
        回复:  thans very much(15字) - lish,2007年9月12日
        回复:  支持-----------------------------------------..(298字) - mycatboys,2007年6月26日
        回复:  继续写出来。(12字) - jx,2007年6月3日
        回复:  好人啊辛苦(12字) - jiafan,2007年5月21日
        回复:  楼主辛苦了!UP UP!(18字) - jingle_even,2007年4月30日
        回复:  继续吧,很好啊咯!(18字) - jx,2007年4月19日
        回复:  支持!鼓励你!(16字) - jx,2007年4月15日
        回复:  有些术语我拿不准,希望大家指出来。(34字) - xml-linguist,2007年4月13日
        回复:  谢谢!我会坚持下去的。我自己要学一遍,顺便贴在这里,希望对初学的人有帮助。..(76字) - xml-linguist,2007年4月13日
            回复:  谢谢支持!学完以后,应该实践了,估计难度更大一点。只有实践,才能真正学会!..(78字) - xml-linguist,2007年4月16日

    W3C Contributing Supporter! W 3 C h i n a ( since 2003 ) 旗 下 站 点
    苏ICP备05006046号《全国人大常委会关于维护互联网安全的决定》《计算机信息网络国际联网安全保护管理办法》
    109.375ms