gembin

OSGi, Eclipse Equinox, ECF, Virgo, Gemini, Apache Felix, Karaf, Aires, Camel, Eclipse RCP

HBase, Hadoop, ZooKeeper, Cassandra

Flex4, AS3, Swiz framework, GraniteDS, BlazeDS etc.

There is nothing that software can't fix. Unfortunately, there is also nothing that software can't completely fuck up. That gap is called talent.

About Me

 

XQuery的一个简单例子(转载)

XQuery的一个简单例子(转载)

来源:中国XML论坛
看到有人问如何使用xquery,其实我也是个菜鸟。
刚刚运行了两个例子,给不会的指个路。
首先下载saxon8.1.1   http://saxon.sourceforge.net/
Saxon-B 8.1.1是免费的,Saxon-SA 8.1.1是有试用期的,前者就够了。
系统要安装jdk1.4.1以上版本,因为saxon是用这个版本写的,但不知道1.3.1行不。
记得设置JAVA_HOME环境变量指向jdk。
然后,试试吧!

例子:文件characters.xml

<characters>
<character>
    <name>Aleria</name>
    <gender>Female</gender>
    <species>Heroleim</species>
    <vocation>Bard</vocation>
    <level>5</level>
    <health>25</health>
</character>
<character>
    <name>Shar</name>
    <gender>Male</gender>
    <species>Human</species>
    <vocation>Merchant</vocation>
    <level>6</level>
    <health>28</health>
</character>
<character>
    <name>Gite</name>
    <gender>Female</gender>
    <species>Aelvar</species>
    <vocation>Mage</vocation>
    <level>7</level>
    <health>18</health>
</character>
<character>
    <name>Horukkan</name>
    <gender>Male</gender>
    <species>Udrecht</species>
    <vocation>Warrior</vocation>
    <level>5</level>
    <health>32</health>
</character>
<character>
    <name>Gounna</name>
    <gender>Female</gender>
    <species>Noleim</species>
    <vocation>Mage</vocation>
    <level>8</level>
    <health>31</health>
</character>
<character>
    <name>Sheira</name>
    <gender>Female</gender>
    <species>Human</species>
    <vocation>Cleric</vocation>
    <level>4</level>
    <health>17</health>
</character>
<character>
    <name>Drue</name>
    <gender>Female</gender>
    <species>Voleim</species>
    <vocation>Warrior</vocation>
    <level>6</level>
    <health>32</health>
</character>
<character>
    <name>Paccu</name>
    <gender>Male</gender>
    <species>Human</species>
    <vocation>Merchant</vocation>
    <level>5</level>
    <health>24</health>
</character>
</characters>

查询文件:Date.xquery
for $character in doc('characters.xml')//character
order by $character/name descending
return
      <dateReport>
            {$character/name}
            
      </dateReport>
(: Stylus Studio meta-information - (c)1998-2003. Sonic Software Corporation. All rights reserved.
<metaInformation>
<scenarios/><MapperInfo><TargetSchema SchemaFilePath="" SchemaRoot="" AssociatedInstance=""/></MapperInfo>
</metaInformation>
:)

在命令提示下,输入:
set classpath=d:\saxon\saxon8.jar (saxon8.jar所在文件夹)
java net.sf.saxon.Query -s characters.xml Date.xquery
ok!
看结果吧!

D:\xml>java net.sf.saxon.Query -s characters.xml Date.xquery
<?xml version="1.0" encoding="UTF-8"?>
<dateReport>
   <name>Sheira</name>
</dateReport>
<dateReport>
   <name>Shar</name>
</dateReport>
<dateReport>
   <name>Paccu</name>
</dateReport>
<dateReport>
   <name>Horukkan</name>
</dateReport>
<dateReport>
   <name>Gounna</name>
</dateReport>
<dateReport>
   <name>Gite</name>
</dateReport>
<dateReport>
   <name>Drue</name>
</dateReport>
<dateReport>
   <name>Aleria</name>
</dateReport>


posted on 2008-01-31 16:32 gembin 阅读(360) 评论(0)  编辑  收藏


只有注册用户登录后才能发表评论。


网站导航:
 

导航

统计

常用链接

留言簿(6)

随笔分类(440)

随笔档案(378)

文章档案(6)

新闻档案(1)

相册

收藏夹(9)

Adobe

Android

AS3

Blog-Links

Build

Design Pattern

Eclipse

Favorite Links

Flickr

Game Dev

HBase

Identity Management

IT resources

JEE

Language

OpenID

OSGi

SOA

Version Control

最新随笔

搜索

积分与排名

最新评论

阅读排行榜

评论排行榜

free counters