Hi All,
I have something going wrong with the XmlTextReader. I have a function that
reads the following XML example. For some reason the code is only getting two
of the 3 Values elements. Here is some code I'm using:
Thanks for any suggestions.
<?xml version="1.0" encoding="windows-1252" ?>
<MMTP>
<LookUp>
<ControlType>C1ComboBoxList</ControlType>
<DBField>LastMedDate</DBField>
<BookMark></BookMark>
<ColumnIndex></ColumnIndex>
<ControlName>cmbGoal5</ControlName>
<Values VALUE="0" BookMark="Goal5Progress"/>
<Values VALUE="1" BookMark="Goal5NoProgress"/>
<Values VALUE="2" BookMark="Goal5NA"/>
</LookUp>
</MMTP>
Private Shared Function FormatXml(ByVal reader As XmlTextReader, ByVal
filename As String) As clsReportElements
Dim ReportElement As clsReportElement
Dim al As new clsReportElements 'ArrayList(117)
Dim lValue as string
Dim lBookmark as String
Try
ReportElement = New clsReportElement
While reader.Read()
Select Case (reader.NodeType)
Case XmlNodeType.Element
'''***Other Elements removed for easy reading*****
If (reader.Name = "Values") Then
dim isValueAdded as Boolean = False
if reader.HasAttributes then
Do while reader.MoveToNextAttribute ()
if len(Reader.Value.Trim) > 0 then
if Reader.Name = "VALUE" then
lValue = Reader.Value
End If
end if
if Reader.Name = "BookMark" then
if len(Reader.Value.Trim) > 0 then
lBookmark = Reader.Value.ToString
isValueAdded = True
end if
End If
Loop
End If
if isValueAdded = True then
ReportElement.AddValue (lValue, lBookmark)
end if
End If
case XmlNodeType.EndElement
If (reader.Name = "LookUp") then
al.Add(ReportElement)
ReportElement = New clsReportElement
End If
case xmlnodetype.Attribute
If (reader.Name = "Values") Then
ReportElement.AddValue (0, reader.ReadElementString())
End If
End Select
End While
Return al
Catch ex As Exception
Console.WriteLine("Operation Failed.")
Console.WriteLine("Exception: {0}", ex.ToString())
Finally
'Finished with XmlTextReader
If Not reader Is Nothing Then
reader.Close()
End If
End Try
End Function
Michael Lee