need to replace XmlValidatingReader is obsolete

Hi, I have the following piece of code and want to replace XmlValidatingReader is obsolete warning...Please help!!!
Imports System.Collections
Imports System.IO
Imports System.Reflection
Imports System.Xml
Imports System.Xml.Schema
 
Imports NUnit.Framework
Imports NUnit.Framework.Constraints
 
Public Class SchemaConstraint
    Inherits Constraint
 
    Private _expectedType As Type
    Private _wasNotExpectedType As Boolean
    Private _validationErrors As ArrayList
    Private _schemaResourceName As String
 
    Public Sub New(ByVal schemaResourceName As String)
        _schemaResourceName = schemaResourceName
        _expectedType = GetType(XmlDocument)
        _wasNotExpectedType = False
        _validationErrors = New ArrayList
    End Sub
 
    Public Overrides Function Matches(ByVal actual As Object) As Boolean
 
        Me.actual = actual
        _validationErrors.Clear()
 
        If Not _expectedType.IsInstanceOfType(actual) Then
            _wasNotExpectedType = True
            Return False
        End If
 
        Dim reader As XmlValidatingReader = New XmlValidatingReader(DirectCast(actual, XmlDocument).OuterXml, XmlNodeType.Document, Nothing)
        Try
 
            Dim schema As XmlSchema= reader.Schemas.Add(Nothing, New XmlTextReader([Assembly].GetExecutingAssembly().GetManifestResourceStream(Me.GetType(), _schemaResourceName)))
            AddHandler reader.ValidationEventHandler, AddressOf ValidationEventHandler
            While reader.Read()
                'do nothing
            End While
            If _validationErrors.Count > 0 Then
                Return False
            End If
 
        Finally
            reader.Close()
        End Try
 
        Return True
 
    End Function

Open in new window

KerauAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

KerauAuthor Commented:
I have seen this and have been trying since  morning but its not happening :( ...can you please guide me as what specific changes do i need to make ..
0
Anurag ThakurTechnical ManagerCommented:
the changes are somewhat similar to what were initially suggested
the XmlValidatingReader was using the following constructor call
http://msdn.microsoft.com/en-us/library/311076dx(VS.80).aspx

you will have to change you validation code to something like this
http://msdn.microsoft.com/en-us/library/8f0h7att(VS.80).aspx

and the xmlreader.create will take this call
http://msdn.microsoft.com/en-us/library/w8k674bf.aspx in which you will supply the xml string
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Upgrade your Question Security!

Your question, your audience. Choose who sees your identity—and your question—with question security.

KerauAuthor Commented:
Thanks !!!! let me try this and get back to you ragi0017
0
KerauAuthor Commented:
ragi0017, I still am having issues with it :(. I need a mentor on this one. I need a mentor on this one. Please help
0
KerauAuthor Commented:
ok ragi your process did help me a lot and i don't see any warnings or error. i wrote a function (see below), but i am not sure as this will be the exact replica of what it's suppose to do.  Please check and correct me if i am wrong..

Thanks
    Public Overridable Function ValidateData() As String()
 
        ' Set the validation settings.
        Dim settings As XmlReaderSettings = New XmlReaderSettings()
        settings.ValidationType = ValidationType.Schema
        settings.ValidationFlags = settings.ValidationFlags Or XmlSchemaValidationFlags.ProcessInlineSchema
        settings.ValidationFlags = settings.ValidationFlags Or XmlSchemaValidationFlags.ReportValidationWarnings
        'AddHandler settings.ValidationEventHandler, AddressOf ValidationCallBack
 
        ' Create the XmlReader object.
        Dim reader As XmlReader = XmlReader.Create("inlineSchema.xml", settings)
        'Dim reader As XmlValidatingReader = New XmlValidatingReader(New XmlTextReader(DataFileName))
        Try
 
            settings.Schemas.Add(Nothing, New XmlTextReader([Assembly].GetExecutingAssembly().GetManifestResourceStream(Me.GetType(), ReportName + ".xsd")))
            AddHandler settings.ValidationEventHandler, AddressOf ValidationEventHandler
 
            _validationErrors.Clear()
            While reader.Read()
                'do nothing
            End While
 
            Return DirectCast(_validationErrors.ToArray(GetType(String)), String())
 
        Finally
            reader.Close()
        End Try
 
    End Function

Open in new window

0
Anurag ThakurTechnical ManagerCommented:
the code looks fine to me but you are the best person to test it as you know best what your requirements
we can help you if you face any issues
all the best - ragi
0
KerauAuthor Commented:
Thanks...for a quick review..if i get any issues i will come back on this thread ..:)
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Visual Basic.NET

From novice to tech pro — start learning today.