Home
Search
 
What's New
Index
Books
Links
Q & A
Newsletter
Banners
 
Feedback
Tip Jar
 
C# Helper...
 
XML RSS Feed
Follow VBHelper on Twitter
 
 
 
MSDN Visual Basic Community
 
 
 
 
 
TitleFind nodes with a particular tag name in an XML file with VB .NET
DescriptionThis example shows how to find nodes with a particular tag name in an XML file with VB .NET.
KeywordsXML, VB.NET, find node
CategoriesOffice
 
This program creates an XmlDocument object and uses its Load method to load the XML file. It then uses the object's GetElementsByTagName to get a list of XmlNode objects that have the indicated name. It loops through those objects, processing them. In this example, the program displays each object's Name attribute and its tag value.
 
' Load the XML file.
Dim xml_doc As New Xml.XmlDocument
xml_doc.Load(txtFile.Text)

' Get the desired children.
Dim child_nodes As XmlNodeList = _
    xml_doc.GetElementsByTagName(txtTagName.Text)

' Process the children.
Dim txt As String = ""
For Each child As XmlNode In child_nodes
    txt &= _
        child.Attributes("Name").InnerXml & " = " & _
        child.InnerText & vbCrLf
Next child

txtResults.Text = txt
 
 
Copyright © 1997-2010 Rocky Mountain Computer Consulting, Inc.   All rights reserved.
  Updated