ARTICLE

Simple XML Parser in VB.NET

Posted by Shehan Peruma Articles | Visual Basic 2010 April 05, 2005
This article shows how to create a very simple XML parser.
Download Files:
 
Reader Level:

This article and the attached source code shows how to parse XML documents using .NET XML class library classes.

The application reads the XML file and then associates the xml tags to variables which are then displayed in a message box.

The namespace System.Xml would be the only additional namespace that we would be using.

Start of by initializing a new instance of the XmlDocument class.

Private xDoc As XmlDocument = New XmlDocument().

Next use the load method to load the XML document from the specified stream.

xDoc.Load("sampleXML.xml").

Use the method GetElementsByTagName() to obtain the addresses of a collection of elements that match the specified name.

Private name As XmlNodeList = xDoc.GetElementsByTagName("myName").
Private age As XmlNodeList = xDoc.GetElementsByTagName("myAge").

XmlNodeList represents an ordered collection of nodes.

Display the results in a message box.

MessageBox.Show("Name: " & name(0).InnerText).

InnerText will return the concatenated values of the node and all its children.

Login to add your contents and source code to this article
share this article :
post comment
 
Team Foundation Server Hosting
Become a Sponsor
PREMIUM SPONSORS
  • The leading .NET charting control now features PDF, Flash and Silverlight export, visualization of large datasets and more. Deliver true charting functionality to your BI, Scorecard, Presentation or Scientific apps. Download evaluation now.
    Get 2 Months Free of ASP.NET Hosting for Only $4.95/month! Receive FREE MS SQL and MySQL Databases Including ASP.NET 4/3.5, MVC 3.0, Silverlight 4, Windows 2008/IIS 7.0 Plus FREE IIS 7 Modules. Host UNLIMITED ASP.NET Web Sites - Click Here!
Nevron Diagram
Become a Sponsor