日期:2014-05-20  浏览次数:21036 次

C# 读XML文件问题,求解!!
目前XML
  <?xml version="1.0" ?> 
- <Configuration>
- <RelationshipCCIp>
  <ccValue>10.137.144.81:21:123:456</ccValue> 
  <ccValue>10.137.144.82:21:123:456</ccValue> 
  <ccValue>10.137.144.83:21:123:456</ccValue> 
  <ccValue>10.137.144.84:21:123:456</ccValue> 
  <ccValue>10.137.144.85:21:123:456</ccValue> 
  <ccValue>10.137.144.86:21:123:456</ccValue> 
  <ccValue>10.137.144.87:21:123:456</ccValue> 
  <ccValue>10.137.144.88:21:123:456</ccValue> 
  </RelationshipCCIp>
 <Configuration>
最终我想把ccValue中的所有数据都提出来?我这样写只能获取第一个?
  List<string> rstInfo = new List<string>();
  string cfgPath = @"d:\Config.xml";
  XmlDocument doc = new XmlDocument();
  try
  {
  doc.Load(cfgPath);
  }
  catch(Exception e)
  {
  MessageBox.Show(e.Message);
  }

  try
  {
  foreach (XmlNode group in doc.SelectNodes(@"Configuration/RelationshipCCIp"))
  {
   
  string info = null;
  XmlNode item;
  item = group.SelectSingleNode("ccValue");
  info = item.InnerText;
  rstInfo.Add(info);
  }

  }
  catch(Exception e)
  {
  MessageBox.Show(e.Message);
  }

------解决方案--------------------
foreach (XmlNode group in doc.SelectNodes(@"Configuration/RelationshipCCIp/ccValue"))
{
rstInfo.Add(group.InnerText);
 ;即可
}