Public Class Test
    Inherits System.Web.UI.Page

    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        If Page.IsPostBack Then
            Dim test = txtTest.Text
            _Parse(test)
            litResult.Text = HttpUtility.HtmlEncode(
                "ErrorReason: " & ErrorReason & vbCrLf &
                "ProviderReferenceId: " & ProviderReferenceId & vbCrLf &
                "ClientReferenceId: " & ClientReferenceId & vbCrLf &
                "SchedulingUrl: " & SchedulingUrl)
        End If
    End Sub
    

    Property ErrorReason As String = Nothing

    Property ProviderReferenceId As String
    Property ClientReferenceId As String
    Property SchedulingUrl As String

    Sub _Parse(data As String)
        ' i3Screen switches randomly between SOAP and not SOAP, 
        ' so we can't just easily deserialize...
        ' We'll just do a search for whatever we want instead.

        If data.Contains("<status>failure") Then
            ErrorReason = Regex.Match(data, "<reason>(.*?)</reason>").Captures(0).Value

        Else
            ProviderReferenceId = Regex.Match(data, "<ProviderReferenceId.*?>(\s*)<IdValue>(\d+)").Groups(2).Value
            ClientReferenceId = Regex.Match(data, "<ClientReferenceId.*?>(\s*)<IdValue>(\d+)").Groups(2).Value
            SchedulingUrl = HttpUtility.UrlDecode(Regex.Match(data, "<SchedulingUrl.*?>(.*?)<\/SchedulingUrl>").Groups(1).Value)
        End If
    End Sub

End Class