This paper mainly introduces the method of reading XML multilevel child nodes in C #. Has a good reference value. Let's take a look at the little series.
If you don't say much, look at the code:
String Xmlfilepath = "D:\\log_xml\\marinfo.xml"; Server.MapPath (@ "relative path such as/xml/test.xml"); XmlDocument doc = new XmlDocument ();d OC. Load (xmlfilepath);//load XML file String rst = "";//Use an XPath expression to select all student child nodes in the document XmlNodeList Studentnodelist = doc. SelectNodes ("Root/marketlist/market"), if (studentnodelist! = null) {foreach (XmlNode studentnode in studentnodelist) {/ /get the attribute named name by Attributes string name = studentnode.attributes["Marketname"]. Value+ ":"; rst+= name;//get Submarketlist Sub-node under current node XmlNode Coursesnode by selectSingleNode method = Studentnode.selectsinglenode ("submarketlist");//Get all the first-level child nodes of Coursenode by ChildNodes property XmlNodeList Coursenodelist = Coursesnode.childnodes;if (coursenodelist! = null) {foreach (XmlNode coursenode in coursenodelist) {rst + = coursenode.attributes["Name"]. Value+ ",";} RST + = "<br/>";}}} Response.Write (RST);