新客网WWW.XKER.COM:致力做中国最专业的网络学院!
学院: 操作系统 - 网络应用 - 服务器 - 网络安全 - 工具软件 - 办公软件 - Web开发 - 数据库 - 网页设计 - 图形图像 - 媒体动画 - 硬件学堂 - 存储频道 - QQ专区
您的位置:首页 > 软件开发 > .Net开发 > Asp.net教程 > 正文:在.Net1.2中对Xquery的支持

在.Net1.2中对Xquery的支持

新客网 XKER.COM 2004-07-16 来源: 收藏本文
在.Net1.2中支持Xquery,Xquery使用一种叫FLWOR的查询语言(音Flower).例子如下:

using System;
using System.IO;
using System.Xml;
using System.Xml.Query;
using System.Data.SqlXml;
namespace XQuery{
public class XQuerySample{
public static void Main(string[] args) {
System.Xml.XmlDataSourceResolver ds = new System.Xml.XmlDataSourceResolver ();
ds.Add("bookstore","books.xml");
StreamWriter writer=new StreamWriter("output.xml");
string query=@"<bookstore> {
for $b in document('bookstore')/bookstore/book
where $b/@genre='philosophy' and $b/@publicationdate='1991'
return $b/title
}
</bookstore>";
XQueryProcessor xp = new XQueryProcessor ();
xp.Compile(query);
xp.Execute(ds, writer);
writer.Close();
}
}
}

books.xml


<?xml version="1.0" encoding="utf-8"?>
<!-- This file represents a fragment of a bookstore database -->
<bookstore>
<book genre="autobiography" publicationdate="1981" ISBN="1-861-11-0">
<title>The Autobiography of Benjamin Franklin</title>
<author>
<first-name>Benjamin</first-name>
<last-name>Franklin</last-name>
</author>
<price>8.99</price>
</book>
<book genre="novel" publicationdate="1967" ISBN="0-201-63361-2">
<title>The Confidence Man</title>
<author>
<first-name>Herman</first-name>
<last-name>Melville</last-name>
</author>
<price>11.99</price>
</book>
<book genre="philosophy" publicationdate="1991" ISBN="1-861001-57-6">
<title>The Gorgias</title>
<author>
<name>Plato</name>
</author>
<price>9.99</price>
</book>
</bookstore>

output.xml

<?xml version="1.0" encoding="utf-8"?>
<bookstore>
<title>The Gorgias</title>
</bookstore>
收藏】 【评论】 【推荐】 【投稿】 【打印】 【关闭
发表评论
要记得去论坛讨论,点击注册新会员匿名评论
评论内容:不能超过250字,需审核后才会公布,请自觉遵守互联网相关政策法规。
阅读排行
随机推荐
实用信息推荐