话不多说,请看代码:
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);
以上就是本文的全部内容,希望本文的内容对大家的学习或者工作能带来一定的帮助,同时也希望多多支持VEVB武林网!
新闻热点
疑难解答