不懂你什么意思?如果要得到其中任何一个东东的值。用Xpath好了。非常方便。
解决方案 »
- |ZYCWCF| 在WCF中,如何判断net.tcp连接的回调已经断开。谢谢
- 高手帮忙看看
- 水晶报表字段更新的问题
- C# stream 大文件,流,分割
- 从数据库中读取图片到页面的问题Response.AddHeader与Response.AppendHeader
- 如何通过鼠标划过事件来改变DIV的CSS
- c# windowsfrom 开发,与界面同步的问题,大家看看,应该怎么办
- 怎么子窗体中直接刷新父窗体的DataGrid控件里面的数据,这个问题问了很多次了,但是没有好的答案。
- 服务端与客户端消息传递
- 如何将csdn去年的贴子转化为xml格式?
- C#中有和c语言一样功能的assert吗?
- 散分啦!
.....XmlDocument doc=new XmlDocument();
doc.Load("文件的名称(包括路径)");XmlNodeList mainTB=doc.GetElementsByTagName("book") ;//第一项book
stirng str = mainTB[0].ChildNodes[0].InnerXml; //<title>题目</title>
str = mainTB[0].ChildNodes[1].InnerXml; //<author>作者</author>
str = mainTB[0].ChildNodes[2].InnerXml; //<content>内容</content>
.....
private const String localURL = "http://localhost/quickstart/howto/samples/Xml/QueryXmlDocumentXPath/cs/books.xml";public static void Main()
{
QueryXmlDocumentXPathSample myQueryXmlDocumentXPathSample = new QueryXmlDocumentXPathSample();
myQueryXmlDocumentXPathSample.Run(localURL);
}public void Run(String args)
{
Console.WriteLine("XPath Test started ..."); XPathDocument myXPathDocument = new XPathDocument(args);
XPathNavigator myXPathNavigator = myXPathDocument.CreateNavigator(); // Get all the book prices
XPathQuery(myXPathNavigator, "descendant::book/price"); // Get the ISBN of the last book
XPathQuery(myXPathNavigator, "bookstore/book[3]/@ISBN");
}private void XPathQuery(XPathNavigator myXPathNavigator, String xpathexpr )
{
try
{
Console.WriteLine("XPath query: " + xpathexpr); // Create a node interator to select nodes and move through them (read-only)
XPathNodeIterator myXPathNodeIterator = myXPathNavigator.Select (xpathexpr); while (myXPathNodeIterator.MoveNext())
{
Console.WriteLine("<" + myXPathNodeIterator.Current.Name + "> " + myXPathNodeIterator.Current.Value);
}
Console.WriteLine();
}
catch (Exception e)
{
Console.WriteLine ("Exception: {0}", e.ToString());
}
}
<?xml version="1.0" encoding="utf-8" ?>
<Root>
<books>
<book>
<title>题目</title>
<author>作者</author>
<content>内容</content>
</book>
<book>
... ...
</book>
... ...
</books>
</Root>
可以使用DataSet.WriteXml() 将文件读入DataSet中,然后DataSet.Tables["books"]中用
DataSet.Tables["books"].Row[0]["title"]和DataSet.Tables["books"].Row[0]["author"]
作为条件过滤得到DataSet.Tables["books"].Row[0]["content"]
个人意见,请你参考.