The classes cRadios:
Imports System.Xml
Public Class cRadio
Public Url As String
Public Genre As String
Public Logo As String
End Class
Public Class cRadios
Inherits Dictionary(Of String, cRadio)
Dim XmlDoc As XmlDocument
Public Sub New(XMLFilename As String)
XmlDoc = New XmlDocument
Try
XmlDoc.Load(XMLFilename)
ReadRadios()
Catch ex As XmlException
Throw New Exception("XML initialisation file is badly formated or corrupted:" & vbCrLf & ex.Message)
Catch ex As Exception
Throw New Exception("Error loading XML " & XMLFilename & vbCrLf & ex.Message)
End Try
End Sub
Private Sub ReadRadios()
Dim xChapter As XmlNodeList
Dim index As Integer = 0
Dim r As cRadio
xChapter = XmlDoc.DocumentElement.ChildNodes
Try
For Each cell As XmlElement In xChapter
r = New cRadio With {.Genre = cell.Attributes("genre").Value}
If cell.HasAttribute("genre") Then
r.Genre = cell.Attributes("genre").Value
End If
If cell.HasAttribute("url") Then
r.Url = cell.Attributes("url").Value
End If
If cell.HasAttribute("icon") Then
r.Logo = cell.Attributes("icon").Value
End If
Me.Add(cell.Attributes("name").Value, r)
Next
Catch ex As NullReferenceException
MsgBox("Probably, some attribute data are missing",, "Error in ReadRadios")
Throw New Exception("Missing attribute(s) in XML ")
Catch ex As Exception
MsgBox(ex.Message,, "Error in ReadRanging ")
End Try
End Sub
End Class