日期:2014-05-17 浏览次数:20449 次
XmlDocument doc = new XmlDocument(); doc.Load("e:\\1.txt"); XmlNodeList nodes = doc.DocumentElement.SelectNodes("Type"); foreach (XmlNode node in nodes) { //node.InnerText,这个就是name的内容,自己判断 }
------解决方案--------------------
string Name1="";
string Name2 = "";
string Name3 = "";
string xmlstr = "<?xml version=\"1.0\" encoding=\"utf-8\"?>";
xmlstr += "<Group><Type><ID>1</ID><Name>MyName 1</Name></Type><Type><ID>2</ID><Name>MyName 2</Name></Type><Type><ID>3</ID><Name>MyName 3</Name></Type></Group>";
XmlDocument doc = new XmlDocument();
doc.LoadXml(xmlstr);
XmlElement root = doc.DocumentElement;
XmlNodeList nodes = root.SelectNodes("Type");
for (int i = 0; i < nodes.Count; i++)
{
XmlNode xmlnode =nodes.Item(i);
switch(xmlnode.SelectSingleNode("ID").InnerText)
{
case "1": Name1 = xmlnode.SelectSingleNode("Name").InnerText; break;
case "2": Name2 = xmlnode.SelectSingleNode("Name").InnerText; break;
case "3": Name3 = xmlnode.SelectSingleNode("Name").InnerText; break;
default: break;
}
}
//Name
------解决方案--------------------
找ID为1的节点:
XmlNode incrementPidUploadNode = domIncrementIndex.SelectSingleNode("/Group/Type/ID[text()='" + 1 + "']");
然后找下个节点,取值便可