http://dev.csdn.net/article/28/28502.shtm
解决方案 »
- 导出excel 放到服务器上导出失败 本地测试成功
- 2345网址导航超链接效果
- 关于两个dataset中数据的比较
- DataGridView单元格编辑完成后事件获得
- 新手请教:怎样删除相同的行???(使用的是access数据库)
- 路过的大大们谁能告诉怎么在C#里的from里面画一个圆圈呀,```不要用控件
- 请教高手,我想在 Toolbar中做一个数据库的备份功能,该怎么做?急!!
- c#(不是JS页面)的一个弹窗函数,不用刷新的
- 会PY的福音...转代码,py转C#,没几行.简单
- 小弟欲学C#,请各位大虾近来指点一二 ……………………
- 关于together中模式的代码自动生成
- 关于动态数组的速度问题,高手老手来拿分,请不要猜测!
如果放到DateSet中用SQL语句我能整
但是我想XML本身应该有更方便的方法
请指教
[C#]
using System;
using System.IO;
using System.Xml;public class Sample
{
public static void Main()
{ XmlDocument doc = new XmlDocument();
doc.Load("booksort.xml"); //Create an XmlNamespaceManager for resolving namespaces.
XmlNamespaceManager nsmgr = new XmlNamespaceManager(doc.NameTable);
nsmgr.AddNamespace("bk", "urn:samples"); //Select and display the value of all the ISBN attributes.
XmlNodeList nodeList;
XmlElement root = doc.DocumentElement;
nodeList = root.SelectNodes("/bookstore/book/@bk:ISBN", nsmgr);
foreach (XmlNode isbn in nodeList){
Console.WriteLine(isbn.Value);
} }}
该示例使用文件 booksort.xml 作为输入。
<?xml version="1.0"?>
<!-- A fragment of a book store inventory database -->
<bookstore xmlns:bk="urn:samples">
<book genre="novel" publicationdate="1997" bk:ISBN="1-861001-57-8">
<title>Pride And Prejudice</title>
<author>
<first-name>Jane</first-name>
<last-name>Austen</last-name>
</author>
<price>24.95</price>
</book>
<book genre="novel" publicationdate="1992" bk:ISBN="1-861002-30-1">
<title>The Handmaid's Tale</title>
<author>
<first-name>Margaret</first-name>
<last-name>Atwood</last-name>
</author>
<price>29.95</price>
</book>
<book genre="novel" publicationdate="1991" bk:ISBN="1-861001-57-6">
<title>Emma</title>
<author>
<first-name>Jane</first-name>
<last-name>Austen</last-name>
</author>
<price>19.95</price>
</book>
<book genre="novel" publicationdate="1982" bk:ISBN="1-861001-45-3">
<title>Sense and Sensibility</title>
<author>
<first-name>Jane</first-name>
<last-name>Austen</last-name>
</author>
<price>19.95</price>
</book>
</bookstore>
{
XmlNodeList book;
XmlDocument doc=new XmlDocument();
doc.Load(filename);
XmlElement root = doc.DocumentElement;
book=root.SelectNodes("//book[@id=1]");
string[] str=new string[book.Count];
for(int i=0;i<book.Count;i++)
{
str[i]=book.Item(i).InnerText.ToString();
}
comboBox1.DataSource=str;
}