There's few ways to achieve that using code:
1)
The best option for you is to use custom class plus
Xml Serialization/Deserialization[
^]:
A Complete Sample of Custom Class Collection Serialization and Deserialization[
^]
XML Serialization and Deserialization: Part-1[
^]
XML Serialization and Deserialization: Part-2[
^]
2)
Another option is to use
Linq to XML[
^].
Dim xcontent As String = "<channels>" & _
" <channel id='1'>" & _
" <name>TVR1</name>" & _
" <protocol>Acestream</protocol>" & _
" <quality>720p</quality>" & _
" <url>http://tvr1</url>" & _
" </channel>" & _
" <channel id='2'>" & _
" <name>Antena 1</name>" & _
" <protocol>Sopcast</protocol>" & _
" <quality>4k</quality>" & _
" <url>http://antena1</url>" & _
" </channel>" & _
" <channel id='3'>" & _
" <name>Kanal D</name>" & _
" <protocol>Standard</protocol>" & _
" <quality>TEEEST</quality>" & _
" <url>http://kanald</url>" & _
" </channel>" & _
" <channel id='4'>" & _
" <name>Radio Pro FM</name>" & _
" <protocol>FMTr</protocol>" & _
" <quality>hd</quality>" & _
" <url>radio</url>" & _
" </channel>" & _
"</channels>"
Dim xdoc As XDocument = XDocument.Parse(xcontent)
Dim chanel2find = "TVR1"
Dim result = xdoc.Descendants("channel") _
.Where(Function(x) x.Element("name") = chanel2find) _
.Select(Function(x) New With _
{ _
.id = x.Attribute("id").Value, _
.name = x.Element("name").Value, _
.protocol = x.Element("protocol").Value, _
.quality = x.Element("quality").Value, _
.url = x.Element("url").Value _
}) _
.SingleOrDefault()
Console.WriteLine("{0}", result.protocol)
3)
Another option is to use custom class + Linq to XML:
class definition:
Public Class Channel
Private iid As Integer = 0
Private sname As String = String.Empty
Private sprotocol As String = String.Empty
Private squality As String = String.Empty
Private surl As String = String.Empty
Public Sub New
End Sub
Public Sub New (ByVal _id As Integer, ByVal _nam As String, ByVal _prot As String, _
ByVal _qty As String, ByVal _url As String)
iid = _id
sname = _nam
sprotocol = _prot
squality = _qty
surl = _url
End Sub
Public Property ID As Integer
Get
Return iid
End Get
Set (value As Integer)
iid = value
End Set
End Property
Public Property Name As String
Get
Return sname
End Get
Set (value As String)
sname = value
End Set
End Property
Public Property Protocol As String
Get
Return sprotocol
End Get
Set (value As String)
sprotocol = value
End Set
End Property
Public Property Quality As String
Get
Return squality
End Get
Set (value As String)
squality = value
End Set
End Property
Public Property Url As String
Get
Return surl
End Get
Set (value As String)
surl = value
End Set
End Property
End Class
Usage:
Dim channels As List(Of Channel) = New List(Of Channel)
channels = xdoc.Descendants("channel") _
.Select(Function(x) New Channel With _
{ _
.ID = x.Attribute("id").Value, _
.Name = x.Element("name").Value, _
.Protocol = x.Element("protocol").Value, _
.Quality = x.Element("quality").Value, _
.Url = x.Element("url").Value _
}) _
.ToList()
Dim c As Channel = channels.Cast(Of Channel) _
.Where(Function(x) x.Name = channel2find) _
.SingleOrDefault()
Console.WriteLine("{0} -> {1}", c.Name, c.Protocol)
Try!
Good Luck!