在.Net1.2中对Xquery的支持

**
** 在.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=@"

1<bookstore> {   
2for $b in document('bookstore')/bookstore/book   
3where $b/@genre='philosophy' and $b/@publicationdate='1991'   
4return $b/title   
5}   
6</bookstore>

";
XQueryProcessor xp = new XQueryProcessor ();
xp.Compile(query);
xp.Execute(ds, writer);
writer.Close();
}
}
}

books.xml

 1<bookstore>
 2<book genre="autobiography" isbn="1-861-11-0" publicationdate="1981">
 3<title>The Autobiography of Benjamin Franklin</title>
 4<author>
 5<first-name>Benjamin</first-name>
 6<last-name>Franklin</last-name>
 7</author>
 8<price>8.99</price>
 9</book>
10<book genre="novel" isbn="0-201-63361-2" publicationdate="1967">
11<title>The Confidence Man</title>
12<author>
13<first-name>Herman</first-name>
14<last-name>Melville</last-name>
15</author>
16<price>11.99</price>
17</book>
18<book genre="philosophy" isbn="1-861001-57-6" publicationdate="1991">
19<title>The Gorgias</title>
20<author>
21<name>Plato</name>
22</author>
23<price>9.99</price>
24</book>
25</bookstore>

output.xml

1<bookstore>
2<title>The Gorgias</title>
3</bookstore>
Published At
Categories with Web编程
Tagged with
comments powered by Disqus