Imports System Imports System.Xml Imports System.IO Imports System.Collections Imports Microsoft.VisualBasic 'http://support.microsoft.com/default.aspx?scid=kb;EN-US;q301225 Public module MyModule Private alName as New ArrayList() Private alAddress as New ArrayList() Private alAge as New ArrayList() Private alOtherElements as new ArrayList() Private alElementNames as New ArrayList() Private alAttributeNames as New ArrayList() Sub Main() 'Dim strFile as String = Application.StartupPath() & "\SavedSnippets\SampleData\Contacts.xml" Dim strPath as String = "C:\Documents and Settings\DGarlen\Desktop\CodeSnippetCompiler\SavedSnippets\SampleData" Dim strFile as String = strPath & "\Contacts.xml" Dim strOutput as String ReadXML_toArrayLists(strFile) ShowArrayLists() Console.Write("Press Enter to Continue") Console.ReadLine() End Sub Sub ShowArrayLists() ShowArrayList(alElementNames, "Element Names") ShowArrayList(alName, "Name Elements") ShowArrayList(alAddress, "Address Elements") ShowArrayList(alAge, "Age Elements") ShowArrayList(alOtherElements, "Other Elements") ShowArrayList(alAttributeNames, "Attribute Names") End Sub Sub ShowArrayList(ByVal al as ArrayList, ByVal strTitle as String) Console.WriteLine("") Console.WriteLine("----------------------") Console.WriteLine(strTitle) Dim strItem as String For each strItem in al Console.WriteLine(" " & strItem) Next End Sub Sub ReadXML_toArrayLists(byVal strXmlFileName as String) Dim reader As XmlTextReader = New XmlTextReader(strXmlFileName) Do While (reader.Read()) Dim strElementName as String Select Case reader.NodeType Case XmlNodeType.Element 'Display beginning of element. strElementName = reader.Name IF NOT alElementNames.Contains(strElementName) THEN alElementNames.Add(strElementName) If reader.HasAttributes Then 'If attributes exist While reader.MoveToNextAttribute() Dim strSubElementName As String = strElementName & "/" & reader.Name Dim strNameVal as String = strSubElementName & ":" & reader.Value IF NOT alAttributeNames.Contains(strNameVal) THEN alAttributeNames.Add(strNameVal) End While End If Case XmlNodeType.Text 'Display the text in each element. Dim strElementValue as String = reader.Value Select Case strElementName Case "Name": alName.Add(strElementValue) Case "Address": alAddress.Add(strElementValue) Case "Age": alAge.Add(strElementValue) Case Else: alOtherElements.Add(strElementName & ": " & strElementValue) End Select Case XmlNodeType.EndElement 'Display end of element. strElementName = "EndElement" End Select Loop End Sub End Module