# vb.net iterate through xDocument with xml Navigator



## mtevans5 (May 18, 2011)

HI, I am relatively new to .net and am writing a web service. I need to be able to receive an xml document, read through some of the nodes to identify some data, then append that data to a file name and store the file on the server with the new name. 

I have a method written based on some data i found on this site (thank you!) and the problem I am having is it won't look through all the Elements but stops at the first one. 

The code is below. If someone can see what I am doing wrong that would be great! Thanks, Maureen

*********start code*************

Dim sDoc As New XmlDocument

sDoc.Load(AexReturnFile)
Dim nav = sDoc.CreateNavigator
Dim dbname As String
Dim msgText As String
nav.MoveToRoot()
nav.MoveToFirstChild()
Do
Loop While nav.MoveToNext
Do
If nav.NodeType = XPathNodeType.Element Then
Do
'if children exist
If nav.HasChildren Then
Do
nav.MoveToFirstChild()
If nav.Name = "message" Then
msgText = nav.Value
End If
If nav.Name = "DbaName" Then
dbname = nav.Value
If Not dbname Is Nothing Then
sDoc.Save("C:\" & dbname & "-" & msgText & ".xml")
End If
End If
Loop While nav.MoveToNext

End If
Loop While nav.MoveToNext
End If
'Loop through the nodes
Loop While nav.MoveToNext

*********end code*************


----------

