C# xml解析

来源:互联网 发布:守望先锋 莫伊拉 数据 编辑:程序博客网 时间:2024/06/06 00:46
System.IO.TextReader tr = new System.IO.StringReader(xmltext);
                    System.Xml.XmlDocument document = new System.Xml.XmlDocument();
                    document.Load(tr);
                    tr.Close();

                    var root = document.DocumentElement;
                    //string version = root.GetAttribute("version");

                    XmlNodeList nodes = root.ChildNodes;
                    foreach (XmlNode n in nodes)
                    {
                        switch (n.Name.ToString())
                        {
                            case "字段5":
                                platforms.Add(Convert.ToInt32(n.InnerText));
                                break;
                            case "字段4":
                                apptypes.Add(Convert.ToInt32(n.InnerText));
                                break;
                            case "字段3":
                                apps.Add(Guid.Parse(n.InnerText));
                                break;
                            case "字段2":
                                version = n.InnerText;
                                break;
                            case "字段1":
                                relation = n.InnerText;
                                break;
                        }
                    }