Reading From Multiple XML Files

This example code demonstrates reading data from multiple XML files. The code below is useful when you need to find specific text inside several XML files. The code uses DOM API, wherein the entire file is read into memory and stored in a hierarchical (tree-based) form to represent all the features of an XML document. This API is recommended if used on a lot of small files.

The file names are stored in a string which is splitted into and array. Using for each loop, it loads the files for further processing. In this case, it extracts data from "post" node list having "approved" status.


Sub ReadXmlFiles()
Dim str As String
Dim strArr() As String
str = "xmlfile1.xml,xmlfile2.xml,xmlfile3.xml"
strArr = str.Split(",")
For Each f As String In strArr
Dim xmldoc As XmlDocument = New XmlDocument()
Dim myNodes As XmlNodeList
xmldoc.Load(Server.MapPath(f))
Dim tnode As XmlNode
myNodes = root.SelectNodes(String.Format("post[status='app']"))
For Each tnode In tNodes
    // do something //
    Next
    Next
End Sub