Explain simple Walk through of XmlReader.
In this part we will do a simple walkthrough of how to use the "XmlReader" class. The Sample for the same is available in both languages (i.e. in C# and VB.NET) which you can find in "WindowsApplicationXMLVBNET" and "WindowsApplicationCSharp" folders. The Task is to load "TestingXML.XML" file and display its data in a message box. You can find "TestingXML.XML" file in "BIN" directory of both folders. Below is the display of the "TestingXML.XML" file and its content.
Figure: - Testing.XML Data
The both projects have command button "CmdLoadXML" which has the logic to load the XML file and display the data in the messagebox. I have pasted only the "CmdLoadXML" command button logic for simplicity. Following are some basic steps done:-
(i)Declared the "XMLTextReader" object and gave the XML file name to load the XML data.
(ii)Read the "XMLTextReader" object until it has data and concatenate the data in the temporary string.
(iii)Finally display the similar in a message box.
Figure: - VB.NET code for XMLReader
Same holds true for C# code as shown below:
Figure: - C# code for XMLReader
Figure: - Data Display for "TestingXML.XML"