' 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.IO
Imports System.Xml

Namespace E
    Public Class Program
        Private Shared Sub Test1()
            Try
                Dim doc As New XmlDocument()
                doc.Load(New StreamReader("C:\Work\dirty.xml"))
                Console.WriteLine(doc.DocumentElement.Name)
            Catch ex As Exception
                Console.WriteLine("Exception as expected")
            End Try
        End Sub
        Private Shared Sub Test2()
            Try
                Dim xmlstr As String = File.ReadAllText("C:\Work\dirty.xml")
                Dim validstart As Integer = xmlstr.IndexOf("<?xml")
                Dim doc As New XmlDocument()
                doc.Load(New StringReader(xmlstr.Substring(validstart)))
                Console.WriteLine(doc.DocumentElement.Name)
            Catch ex As Exception
                Console.WriteLine("Exception unexpected")
            End Try
        End Sub
        Public Shared Sub Main(args As String())
            Test1()
            Test2()
            Console.ReadKey()
        End Sub
    End Class
End Namespace
