C# code example sharing for parsing XML files

黄舟
Release: 2017-03-20 13:25:21
Original
2321 people have browsed it

C#Sharing of code examples for parsing XML files

 XmlNodeReader reader = null;
            try
            {
                XmlDocument xd = new XmlDocument();
                xd.Load(filename);
                reader = new XmlNodeReader(xd); //创建新的XML reader
                string nodeType = null;
                while (reader.Read())
                {
                    switch (reader.NodeType)
                    { 
                         case XmlNodeType.Element://判断读到的是否为节点
                            nodeType = reader.Name;
                            break;
                        case XmlNodeType.Text://判断读到的是否为节点值
                            switch (nodeType)
                            {
                                case ROOT:
                                    rootValue = reader.Value;
                                    break;
                                default:
                                    break;
                            }
                            break;
                        default:
                            break;
                    }
                }
            }
            catch (Exception e)
            {
                System.Console.WriteLine("Read XML File Error:" + e.Message + e.StackTrace);
            }
            finally
            {
                if (reader != null)
                {
                    reader.Close();
                }
            }
......................
最后不要忘记把reader close 掉
Copy after login

In fact, this method can be used to reduce the number of command line parameters. Number, now you only need to add a file name. But you need to write the parameters in the file

The above is the detailed content of C# code example sharing for parsing XML files. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!