Imports System.Xml Imports System.Reflection Public Class BiztalkValidate Public Shared Function ValidateDocument(ByVal businessDocument As XmlDocument, ByVal schemaStrongName As String) As String ValidateDocument = "FALSE" ' Constants Const PARTS_IN_SCHEMA_STRONG_NAME As Integer = 2 Const PART_CLASS_NAME As Integer = 0 Const PART_QUALIFIED_ASSEMBLY_NAME As Integer = 1 Try ' Parse schema strong name Dim assemblyNameParts As String() = schemaStrongName.Split(New Char() {","c}, PARTS_IN_SCHEMA_STRONG_NAME) Dim className As String = assemblyNameParts(PART_CLASS_NAME).Trim() Dim fullyQualifiedAssemblyName As String = assemblyNameParts(PART_QUALIFIED_ASSEMBLY_NAME).Trim() ' Load assembly Dim schemaAssembly As [Assembly] = [Assembly].Load(fullyQualifiedAssemblyName) ' Create instance of the BTS schema in order to get to the actual schemas Dim schemaType As Type = schemaAssembly.GetType(className) Dim btsSchemaCollection As Microsoft.XLANGs.BaseTypes.SchemaBase = CType(Activator.CreateInstance(schemaType), Microsoft.XLANGs.BaseTypes.SchemaBase) ' Set up XML validating reader and validate document Dim parserContext As New XmlParserContext(Nothing, Nothing, "", XmlSpace.None) Dim reader As New XmlValidatingReader(businessDocument.OuterXml, XmlNodeType.Document, parserContext) reader.ValidationType = ValidationType.Schema reader.Schemas.Add(btsSchemaCollection.SchemaCollection) Try While reader.Read() End While Catch ex As Exception Throw New Exception(ex.Message) End Try ValidateDocument = "TRUE" Catch e As Exception ValidateDocument = e.Message End Try End Function 'ValidateDocument End Class