C#中读取XML节点值

<?xml version="1.0" encoding="utf-8" ?>
- <Main>
- <AdParameter>
- <ad>
  <URL>C:\Documents and Settings\Administrator\桌面\1\003.jpg</URL>
  <AdID>0001</AdID>
  </ad>
- <ad>
  <URL>C:\Documents and Settings\Administrator\桌面\1\004.jpg</URL>
  <AdID>0002</AdID>
  </ad>
- <ad>
  <URL>C:\Documents and Settings\Administrator\桌面\1\005.jpg</URL>
  <AdID>0003</AdID>
  </ad>
  </AdParameter>
  </Main>
List<string> listADIDs = new List<string>();
XmlDocument xmldoc = new XmlDocument();
xmldoc.Load("E:/studyTest/WindowsApplication2/WindowsApplication2/ShowJPG.xml");//里面是XML的路径
XmlNodeList AdIDList = xmldoc.SelectNodes("//Main/AdParameter/ad/AdID");//从跟节点→父节点→本节的
foreach (XmlNode nl in AdIDList)
{
 listADIDs.Add(nl.InnerText.ToString());
}
这样就可以获得ADID节下的值了。它们在一个listADIDs里存储。
其他的以此类推。就ok了..
posted @ 2009-08-08 21:33  风飘零  阅读(2254)  评论(0编辑  收藏  举报