' Collection of code snippets by Arne Vajhøj 
' (likely posted to comp.os.vms/INFO-VAX, INFO-TPU, MACRO32, eksperten.dk, newz.dk, LinkedIn or other place sometime between 1990 and now) 
Imports System
Imports System.Xml

Namespace E
    Public Class Program
        Public Shared Sub TopList(fromp As Integer, top As Integer)
            Console.WriteLine("TopList " & fromp & " " & top)
        End Sub
        Public Shared Sub Echo(val As String)
            Console.WriteLine("Echo " & val)
        End Sub
        Public Shared Sub Process(xml As String)
            Dim doc As New XmlDocument()
            doc.LoadXml(xml)
            Dim func As String = doc.SelectSingleNode("/request/function/text()").Value
            Dim n As XmlNode = doc.SelectSingleNode("/request/parameters")
            Select Case func
                Case "TOPLIST"
                    Dim fromp As Integer = Integer.Parse(n.SelectSingleNode("from/text()").Value)
                    Dim top As Integer = Integer.Parse(n.SelectSingleNode("to/text()").Value)
                    TopList(fromp, top)
                    Exit Select
                Case "ECHO"
                    Dim val As String = n.SelectSingleNode("val/text()").Value
                    Echo(val)
                    Exit Select
                Case Else
                    Throw New Exception("Unknown function")
            End Select
        End Sub
        Public Shared Sub Main(args As String())
            Dim s1 As String = "<request><function>TOPLIST</function><parameters><from>1</from><to>2</to></parameters></request>"
            Dim s2 As String = "<request><function>ECHO</function><parameters><val>ABC</val></parameters></request>"
            Process(s1)
            Process(s2)
        End Sub
    End Class
End Namespace
