ckelsoe
Member
I have been struggling with reading an XML file. I am doing fine until I get to the repeating data. I do not know how to iterate through the data between the <iterations> tags. I am somehow missing the obvious and would appreciate someone better versed in VB and XML taking a look at my code.
I have attached the data file - just remove the .txt extension.
Thanks, Charles
I have attached the data file - just remove the .txt extension.
Thanks, Charles
VB.NET:
Dim strFileName As String = GetApplicationPath() & "\fml\11109155.fml"
Dim xml_text_reader As New XmlTextReader(strFileName)
Dim intIteration As Short = 0
Me.Cursor = Cursors.WaitCursor
Console.Write("Starting parsing file " & strFileName & ControlChars.CrLf)
'Skip whitespace
xml_text_reader.WhitespaceHandling = WhitespaceHandling.None
' Read first start tag.
xml_text_reader.Read()
'Process each tag item
Do While Not xml_text_reader.EOF
If xml_text_reader.GetAttribute("form") = "US250801" Then
Console.Write("Form " & xml_text_reader.GetAttribute("form") = "US250801" & " was found. Continue processing." & ControlChars.CrLf)
xml_text_reader.Read()
End If
If xml_text_reader.GetAttribute("name") = "5BIS0101" Then
'Grab the field name
Console.Write("The customer's name is: " & xml_text_reader.GetAttribute("field") & ControlChars.CrLf)
' Now go to the iteration elements
Do
' THIS IS WHERE I HAVE PROBLEMS
If xml_text_reader.Name = "iteration" Then
Status("Found iteration: ")
xml_text_reader.Read()
xml_text_reader.Read()
Select Case xml_text_reader.ReadElementString("name")
Case "9AOI5601"
Console.Write("Field " & xml_text_reader.ReadElementString("name") & " and contains the following: " & xml_text_reader.ReadElementString("field") & ControlChars.CrLf)
Case "9AOI5701"
Console.Write("Field " & xml_text_reader.ReadElementString("name") & " and contains the following: " & xml_text_reader.ReadElementString("field") & ControlChars.CrLf)
Case "ATTENT01"
Console.Write("Field " & xml_text_reader.ReadElementString("name") & " and contains the following: " & xml_text_reader.ReadElementString("field") & ControlChars.CrLf)
Case "5AOI0501"
Console.Write("Field " & xml_text_reader.ReadElementString("name") & " and contains the following: " & xml_text_reader.ReadElementString("field") & ControlChars.CrLf)
Case "9AOI5101"
Console.Write("Field " & xml_text_reader.ReadElementString("name") & " and contains the following: " & xml_text_reader.ReadElementString("field") & ControlChars.CrLf)
Case "9AOI5201"
Console.Write("Field " & xml_text_reader.ReadElementString("name") & " and contains the following: " & xml_text_reader.ReadElementString("field") & ControlChars.CrLf)
Case "9AOI5301"
Console.Write("Field " & xml_text_reader.ReadElementString("name") & " and contains the following: " & xml_text_reader.ReadElementString("field") & ControlChars.CrLf)
Case "9AOI5401"
Console.Write("Field " & xml_text_reader.ReadElementString("name") & " and contains the following: " & xml_text_reader.ReadElementString("field") & ControlChars.CrLf)
Case "9AOI5501"
Console.Write("Field " & xml_text_reader.ReadElementString("name") & " and contains the following: " & xml_text_reader.ReadElementString("field") & ControlChars.CrLf)
Case "CANCEL01"
Console.Write("Field " & xml_text_reader.ReadElementString("name") & " and contains the following: " & xml_text_reader.ReadElementString("field") & ControlChars.CrLf)
Case Else
xml_text_reader.Skip()
End Select
Else
xml_text_reader.Skip()
End If
Loop
Else
xml_text_reader.Skip()
End If
Loop
xml_text_reader.Close()
Console.Write("Finished Process" & ControlChars.CrLf)
Me.Cursor = Cursors.Default
Attachments
Last edited: