Hi all,
As you know, the XMLValidatingReader is deprecated in .NET 2.0. I have the
following snippet from a .NET 1.1 implementation that I am struggling to
upgrade. I know I should use XMLReader.Create, but am struggling to get much
further. Any help would be appreciated. Thanks.
Public Shared Sub ValidateDocument(businessDocument As XmlDocument,
schemaStrongName As String)
' 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
' 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).Tr im()
' 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.SchemaColle ction)
While reader.Read()
End While
End Sub 'ValidateDocument
--
John