XML文件如下
<?xml version="1.0" encoding="utf-8" ?>
<root>
<Servers>
<Server ID="1" Name="22"></Server>
<Server ID="2" Name="33"></Server></Servers>
</root>
我想输出每个server的Name属性
我写了一些代码如下
private XmlDocument xDoc;
private XmlNode xNode;
private XmlElement xElem;
this.xDoc=new XmlDocument();
this.xDoc.Load(Application.ExecutablePath+"Server.xml");
this.xNode=this.xDoc.SelectSingleNode("//Servers");
XmlNode _xNode;但是后面写不下去了,我想是应该用foreach循环输出xNode.ChildNodes,还请写段完整的代码,谢谢
<?xml version="1.0" encoding="utf-8" ?>
<root>
<Servers>
<Server ID="1" Name="22"></Server>
<Server ID="2" Name="33"></Server></Servers>
</root>
我想输出每个server的Name属性
我写了一些代码如下
private XmlDocument xDoc;
private XmlNode xNode;
private XmlElement xElem;
this.xDoc=new XmlDocument();
this.xDoc.Load(Application.ExecutablePath+"Server.xml");
this.xNode=this.xDoc.SelectSingleNode("//Servers");
XmlNode _xNode;但是后面写不下去了,我想是应该用foreach循环输出xNode.ChildNodes,还请写段完整的代码,谢谢
System.Xml.XmlDocument xmlDoc = new System.Xml.XmlDocument();
xmlDoc.LoadXml(xml);
System.Xml.XmlNodeList nList = xmlDoc.SelectNodes("//server");
for (int i=0; i<nList.Count; i++)
{
Consolse.WriteLine(nList[i].Attribute["name"].Value);
}