In.. net development often needs to read and write xml files (app. config and web. config is a special column of the xml file used in WinForm and WebForm respectively, and Microsoft provides a general method, so we will not repeat it here ),. the. net class library provides a variety of methods for reading and writing xml files. Each method has its advantages and disadvantages, so it is practical. In.. net development often needs to read and write xml files (app. config and web. config is a special column of the xml file used in WinForm and WebForm respectively, and Microsoft provides a general method, so we will not repeat it here ),. the. net class library provides a variety of methods for reading and writing xml files. Each method has its advantages and disadvantages, so it is practical.
The following lists the classes for reading and writing xml files provided by the Microsoft. net class library and their features:
Class name |
Advantages |
Disadvantages |
XmlReader |
Fast, efficient, and scalable |
Read-only, only forward, manual verification required |
XmlDocument |
Round-trip, read/write, and support for XPath filtering |
Slower than XmlReader |
XPathNavigator |
Round-trip: supports XPath and XSLT |
Read-only |
XPathDocument |
Better than XmlDocument, supports XPath and XSLT optimization |
Slower than XmlReader |
The XmlReader mentioned in this article is also a class in the Microsoft class library. it features fast, efficient, and scalable. Its disadvantage is read-only.
The following example describes how to use XmlReader:
(1) xml file used: meu. xml
(2) read and display: ReadXml. aspx
(2) read and display: ReadXml. aspx <% @ Page Language = "C #" ContentType = "text/html" ResponseEncoding = "gb2312" %> <% @ Import Namespace = "System. xml "%>
XMLReader instance