Parse XML and parse xml files
Xml parsing method:
1 public static Dictionary <int, List <string> ReadingXml (string xmlTxt, string FatherName) 2 {4 XmlDocument xmlDoc = new XmlDocument (); 5 // load xml Document 6 xmlDoc. loadXml (xmlTxt); 7 // find FatherName [FatherName: xml file outermost parent node] 8 XmlNode root = xmlDoc. selectSingleNode (FatherName); 9 10 // obtain all the child nodes of FatherName 11 XmlNodeList nodeList = xmlDoc. selectSingleNode (FatherName ). childNodes; // item node 12 13 List <string> list = null; 14 Dictionary <int, List <string> dic = new Dictionary <int, list <string> (); 15 int key = 0; 16 // traverse all subnodes 17 foreach (XmlNode xn in nodeList) 18 {19 XmlElement xe = (XmlElement) xn; // item20 XmlNodeList subList = xe. childNodes; // item's subnode 21 22 list = new List <string> (); 23 foreach (XmlNode xmlNode in subList) 24 {25 // the value required 26 list. add (xmlNode. innerText); 27} 28 dic. add (key, list); 29 key ++; 30} 31 return dic; 32}
The xml file is flexible. The content in the node is set according to requirements. to parse the xml file, you need to determine the writing method based on the actual situation and requirements of the xml file. The above method is suitable for simple xml parsing.