string path = @"E:\x.xml"; XmlDocument xml = new XmlDocument(); xml.Load(path); XmlNodeList node= xml.SelectNodes("//name"); foreach (XmlNode n in node) Console.WriteLine(n.InnerText); Console.ReadLine();
public XmlDocument xml = new XmlDocument(); string path = @"E:"; string[] file = Directory.GetFileSystemEntries(path); dgvPathWay.Rows.Clear(); for (int i = 0; i < file.Length; i++) { xml.Load(file[i]); XmlElement root = xml.DocumentElement; DataGridView view = new DataGridView(); int index = dgvPathWay.Rows.Add(view); dgvPathWay.Rows[index].Cells["name"].Value = root.Name; dgvPathWay.Rows[index].Cells["dept"].Value = root.GetAttribute(""); }
<Resp>
<H>
<Ver>版本号</Ver>
<Sc>状态码</Sc>
<Msg>返回消息</Msg>
</H>
</Resp>
其次,你可以用一下代码取得你想要的值:
public static void HandleXML()
{
XmlDocument xmldoc = new XmlDocument();
xmldoc.Load("C:\\11.xml");
XmlNode xnRoot = xmldoc.SelectSingleNode("Resp");
XmlNodeList nodelist = xnRoot.ChildNodes;
foreach (XmlNode node in nodelist)
{
string Msg=node.SelectSingleNode("Msg").InnerXml;
if (Msg !="")
{
//在此Msg 就是你想要的值
Console.WriteLine(Msg);
}
}
}
XmlDocument xml = new XmlDocument();
xml.Load(path);
XmlNodeList node= xml.SelectNodes("//name");
foreach (XmlNode n in node)
Console.WriteLine(n.InnerText);
Console.ReadLine();
public XmlDocument xml = new XmlDocument(); string path = @"E:";
string[] file = Directory.GetFileSystemEntries(path);
dgvPathWay.Rows.Clear();
for (int i = 0; i < file.Length; i++)
{
xml.Load(file[i]);
XmlElement root = xml.DocumentElement;
DataGridView view = new DataGridView();
int index = dgvPathWay.Rows.Add(view);
dgvPathWay.Rows[index].Cells["name"].Value = root.Name;
dgvPathWay.Rows[index].Cells["dept"].Value = root.GetAttribute("");
}