Parse XML and parse xml files

Source: Internet
Author: User

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.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.