betway必威-betway必威官方网站
做最好的网站

读取XML多级子节点

string xmlFilePath = "D:\log_xml\MarInfo.xml"; //Server.MapPath(@"相对路径如/xml/test.xml");
XmlDocument doc = new XmlDocument();
doc.Load(xmlFilePath);//加载XML文件
string rst = "";
//使用xpath表达式选择文档中所有的student子节点
XmlNodeList studentNodeList = doc.SelectNodes("Root/MarketList/Market");
if (studentNodeList != null)
{
foreach (XmlNode studentNode in studentNodeList)
{
//通过Attributes获得属性名字为name的属性
string name = studentNode.Attributes["MarketName"].Value ":";
rst = name;

c#读取XML多级子节点,

string xmlFilePath = "D:\log_xml\MarInfo.xml"; //Server.MapPath(@"相对路径如/xml/test.xml");
XmlDocument doc = new XmlDocument();
doc.Load(xmlFilePath);//加载XML文件
string rst = "";
//使用xpath表达式选择文档中所有的student子节点
XmlNodeList studentNodeList = doc.SelectNodes("Root/MarketList/Market");
if (studentNodeList != null)
{
foreach (XmlNode studentNode in studentNodeList)
{
//通过Attributes获得属性名字为name的属性
string name = studentNode.Attributes["MarketName"].Value ":";
rst = name;

//通过SelectSingleNode方法获得当前节点下的SubMarketList子节点
XmlNode coursesNode = studentNode.SelectSingleNode("SubMarketList");

//通过ChildNodes属性获得courseNode的所有一级子节点
XmlNodeList courseNodeList = coursesNode.ChildNodes;
if (courseNodeList != null)
{
foreach (XmlNode courseNode in courseNodeList)
{

rst = courseNode.Attributes["Name"].Value ",";

}
rst = "<br/>";
}

}
}
Response.Write(rst);

string xmlFilePath = "D:\log_xml\MarInfo.xml";//Server.MapPath(@"相对路径如/xml/test.xml"); XmlDocument doc = new XmlDocument(); doc.Load(xmlFi...

//通过SelectSingleNode方法获得当前节点下的SubMarketList子节点
XmlNode coursesNode = studentNode.SelectSingleNode("SubMarketList");

//通过ChildNodes属性获得courseNode的所有一级子节点
XmlNodeList courseNodeList = coursesNode.ChildNodes;
if (courseNodeList betway必威官方网站,!= null)
{
foreach (XmlNode courseNode in courseNodeList)
{

本文由betway必威发布于编程开发,转载请注明出处:读取XML多级子节点

TAG标签: betway必威
Ctrl+D 将本页面保存为书签,全面了解最新资讯,方便快捷。