- 类
XmlReader: 类是一个提供非缓存的、只进只读访问的抽象基类。
XmlReader 类还定义了使您能够从 XML 提取数据或跳过不需要的记录的方法
- 属性
XmlDocument doc = new XmlDocument();
Node.ChildNodes
Node.ParentNode
Node.InnerText
Node.Value
- 方法
XmlNode logstatus = doc.SelectSingleNode("NewDataSet/TestSummary/Status");
Node.SelectSingleNode("");
XmlNodeList studentNodeList = doc.SelectNodes("/students/student");
- 使用
using System;
using System.Collections.Generic;
using System.Text;
using System.Xml;
namespace XmlExample
{
class Program
{
static void Main(string[] args)
{
string xmlFilePath = @" ";
XmlDocument doc = new XmlDocument();
doc.Load(xmlFilePath);
XmlNodeList studentNodeList = doc.SelectNodes("/students/student");
if (studentNodeList != null)
{
foreach (XmlNode studentNode in studentNodeList)
{
string name = studentNode.Attributes["name"].Value;
Console.WriteLine("Student:" + name);
XmlNode coursesNode = studentNode.SelectSingleNode("courses");
XmlNodeList courseNodeList = coursesNode.ChildNodes;
if (courseNodeList != null)
{
foreach (XmlNode courseNode in courseNodeList)
{
Console.Write("\t");
Console.Write(courseNode.Attributes["name"].Value);
Console.Write("老师评语");
XmlNode teacherCommentNode = courseNode.FirstChild;
XmlCDataSection cdata = (XmlCDataSection)teacherCommentNode.FirstChild;
Console.WriteLine(cdata.InnerText.Trim());
}
}
}
}
Console.Write("\r\nPress any key to continue....");
Console.Read();
}
}
}
string s="……"
XmlDocument doc = new XmlDocument();
doc.LoadXml(s);
XmlNode logstatus = doc.SelectSingleNode("NewDataSet/TestSummary/Status");