在.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>
