You should be able to use LINQ's Concat to combine the two collections, which you can then iterate over:
For Each node As XmlNode In _
aDoc.SelectNodes("//*").Cast(Of XmlNode)().Concat( _
eDoc.SelectNodes("//*").Cast(Of XmlNode)())
Or, to make it readable:
Dim l_aNodes = aDoc.SelectNodes("//*").Cast(Of XmlNode)()
Dim l_eNodes = eDoc.SelectNodes("//*").Cast(Of XmlNode)()
Dim l_allNodes = l_aNodes.Concat( l_eNodes )
For Each l_node in l_allNodes
This will take all of the elements from the first collection and then append all of the elements from the second collection to the end of it (like a queue).
Alternatively, if you want to "zip" them, you can use Enumerable.Zip:
If Not l_aNodes.Count = l_eNodes.Count Then
...
End If
Dim l_allNodes =
Enumerable.Zip(
l_aNodes,
l_eNodes,
Function(a, e) New With { .aNode = a, .eNode = e } )
For Each l_aeNode in l_allNodes
If Not l_aeNode.aNode.Name = l_aeNode.eNode.Name Then
...
According to the documentation for Enumerable.Zip,
If the sequences do not have the same number of elements, the method merges sequences until it reaches the end of one of them. For example, if one sequence has three elements and the other one has four, the result sequence will have only three elements.
So you'll need to compare the collections sizes before you begin. It's actually a good idea, as it will save the processing power necessary to compare each individual node.
If the collections are the same size, then code above starts with the first element in each collection and then combines them into an Anonymous Type. Then the second element from each collection, then the third, etc. The result is a collection of the anonymous type instances.
You can then iterate over the anonymous type instances and get each element out using the appropriate property (aNode
and eNode
).
But is there some built-in syntax to handle this? No, there is not.