Problem with XMLValidatingReader?

Problem with XMLValidatingReader?

Post by raghurama » Fri, 02 Apr 2004 19:46:36


Hi,
I have a large xml file to process (~ 70 mb). I am trying to use
XMLValidating reader. The first step was to try out the example in
quickstart samples with minor modifications [significant portions
below]. My intention is to validate the file against a DTD before
processing and to collect all validation errors in a single pass.

Public Class ValidationReadingXMLSample

Private WithEvents myXmlValidatingReader As XmlValidatingReader
Private myXmlTextReader As XmlTextReader

Private Sub Validate()

Try
Dim valdel As ValidationEventHandler = New
ValidationEventHandler(AddressOf ValidationEvent)

While myXmlValidatingReader.Read()
End While

Console.WriteLine("Validation finished. Validation {0}",
s)
Catch e As XmlException
Console.WriteLine("XmlException: {0} ", e.ToString())
Catch e As Exception
Console.WriteLine("Exception: {0} ", e.ToString())
End Try
End Sub

Public Sub ValidationEvent(ByVal errorid As Object, ByVal args As
ValidationEventArgs) Handles
myXmlValidatingReader.ValidationEventHandler

Console.WriteLine(Strings.Chr(9) & "Validation error: " &
args.Message)

If (args.Severity = XmlSeverityType.Warning) Then
Console.WriteLine("No schema found to enforce
validation.")
ElseIf (args.Severity = XmlSeverityType.Error) Then
Console.WriteLine("validation error occurred when
validating the instance document.")
End If

If Not (args.Exception Is Nothing) Then ' XSD schema
validation error
Console.WriteLine(args.Exception.SourceUri & "," &
args.Exception.LinePosition & "," & args.Exception.LineNumber)
End If

End Sub

End Class


The sample works fine for the first 3 errors and then throws an
exception at

While myXmlValidatingReader.Read()

due to which the rest of the file is not being processed. Is this the
way it's supposed to work? This does not solve my problem of trying to
parse the whole file and getting all the errors in one go.

Furthermore, the following code works as follows

While Not myXmlValidatingReader.EOF
Try
While myXmlValidatingReader.Read()
End While
Catch e As XmlException
Console.WriteLine("XmlException: {0} ",
e.ToString())
myXmlValidatingReader.Read()
End Try
End While

But I fail to understand that if this line
While myXmlValidatingReader.Read()
throws an exception, how is it that the line in the catch block
succeeds
myXmlValidatingReader.Read()


Thanks in advance,
Raghu