XML Digest
Composition. NET platform is one of the key technologies is XML, here is a simple talk about how to use. NET in the XmlReader.
1. XmlReader Introduction
XmlReader is a fast, buffer-free, forward-read cursor that reads XML documents and hides the complexity of underlying data exchange. XmlReader as a "pull model" than the "push model" of sax has a variety of advantages, the most important one is that it easier to use, followed by more performance, and reduce the difficulty of programming.
The XmlReader class is an abstract class, Xmltextreader,xmlvalidatingreader, and XmlNodeReader classes inherit from the XmlReader class. The XmlReader class has a number of methods and properties for reading the contents of an XML file, finding the depth of an XML element, determining whether the contents of the current element are empty, and navigating the attributes of the XML.
2. XmlReader application
In the. NET architecture, XML classes are defined in the System.Xml namespace, such as: XmlReader, XmlTextReader, XmlValidatingReader, XmlNodeReader, XmlWriter, And XmlTextWriter, so you should introduce System.Xml when using XmlReader.
The following is a simple console program that reads XML.
[Visual Basic]
Imports System
Imports System.Xml
Module Module1
Sub Main (ByVal Cmdargs () as String)
Try
Dim sfilename as String = Cmdargs (0)
Dim XTR as New XmlTextReader (sFileName)
Xtr. Read ()
Console.WriteLine ("<{0}>"), XTR. Name)
Console.WriteLine (XTR. ReadInnerXml ())
Console.WriteLine ("</{0}>"), XTR. Name)
Xtr. Close ()
Catch Eerr as Exception
Console.WriteLine ("Error:\t{0}", Eerr.message)
End Try
End Sub
End Module
The XML file used by the test, People.xml
<People>
<Person>
<Name>
<FirstName>Joe</FirstName>
<LastName>Suits</LastName>
</Name>
<Address>
<street>1800 Success way</street>
<City>Redmond</City>
<State>WA</State>
<ZipCode>98052</ZipCode>
</Address>
<Job>
<Title>CEO</Title>
<description>wears the Nice suit</description>
</Job>
</Person>
<Person>
<Name>
<FirstName>Linda</FirstName>
<LastName>Sue</LastName>
</Name>
<Address>
<street>1302 American st.</street>
<city>paso robles</city>
<State>CA</State>
<ZipCode>93447</ZipCode>
</Address>
<Job>
<Title>Attorney</Title>
<description>stands up for Justice</description>
</Job>
</Person>
</People>
You can run a program by calling a command prompt, such as: E:\>consoleapplication_xmlreader.exe People.xml
3. Summary
. NET XmlReader provides a good interface for accessing XML data, making it easier for developers to read the contents of XML files and make them quick to use. NET becomes possible.
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.