读取xml数据

前端之家收集整理的这篇文章主要介绍了读取xml数据前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。

xml:

<?xml version="1.0" encoding="GB2312" standalone="yes" ?>

<App appId="131746922" appName="上传我的应用"appType="2" programPath="" mainProg="" publishTime="2012-12-26 00:00:00" userId="" />
<ProgramConf >
<AdvURLs timeInterval="4" advFlag="0">
<Item adId="1" advName="ad01" advUrl="ad01.html" sort="4" advFlag="0" />
<Item adId="2" advName="ad02" advUrl="ad02.html" sort="3" advFlag="0" />
<Item adId="3" advName="ad03" advUrl="ad03.html" sort="2" advFlag="0" />
<Item adId="4" advName="ad04" advUrl="ad04.html" sort="1" advFlag="0" />
</AdvURLs>
<AdvSetup>
<Item name="我要分享" flag="1" sort="6" Url="http://xxx/share.aspx" />
<Item name="求资源" flag="1" sort="5" Url="http://xxx/needs.aspx" />
<Item name="报错误" flag="1" sort="4" Url="http://xxx/errors.aspx" />
<Item name="提建议" flag="1" sort="3" Url="http://xxx/advice.aspx" />
<Item name="上传我的应用" flag="1" sort="2" Url="http://xxx/" />
<Item name="联系我们" flag="1" sort="1" Url="http:/xxx/" />
</AdvSetup>
<LocalIp>10.122.51.30</LocalIp>
<applyFlag>0</applyFlag>
<applyUrl></applyUrl>
</ProgramConf>


c#代码

stringxmlpath ="xxx.xml";

XmlDocument xmlDoc = new XmlDocument();
xmlDoc.Load(xmlpath);
XmlNodeList nodeList = xmlDoc.SelectSingleNode("ProgramConf/AdvSetup").ChildNodes;//获取Employees节点的所有子节点
foreach (XmlNode xn in nodeList)//遍历所有子节点
{
XmlElement xe = (XmlElement)xn;

stringName = xe.GetAttribute("name");
stringValue = xe.GetAttribute("Url");
string Sort = xe.GetAttribute("sort");

}


XmlElement xe2 = (XmlElement)xmlDoc.SelectSingleNode("App"); string AppID = xe2.GetAttribute("appId"); string AppName = xe2.GetAttribute("appName");

猜你在找的XML相关文章