⌘BABAKOV.NET Let's code!
100% [dark] [ru]

Simple XML File Processing Example in C#.

XML File Processing Example in C#.

A simple example that clearly shows how easy it is to break down an XML file into pieces.

string prm = "";

            XmlTextReader reader = new XmlTextReader(fi.Name.Replace(fi.Extension, ".XML"));

            while (reader.Read())
            {
                switch (reader.NodeType)
                {
                    case XmlNodeType.Element: // Узел является элементом.
                        prm = prm + ("<" + reader.Name);

                        while (reader.MoveToNextAttribute()) // Чтение атрибутов.
                            prm = prm + (" " + reader.Name + "=\'" + reader.Value + "\'");
                        prm = prm + (">");
                        break;
                    case XmlNodeType.Text: // Вывести текст в каждом элементе.
                        prm = prm + (reader.Value);
                        break;
                    case XmlNodeType.EndElement: // Вывести конец элемента.
                        prm = prm + ("</" + reader.Name);
                        prm = prm + (">");
                        break;
                }
            }
            MessageBox.Show(prm);
            reader.Close();

Comments (0)

No comments yet.

Leave a comment
Comment
Images (up to 5 MB)
Your comment will appear after moderation.