473,241 Members | 2,045 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,241 software developers and data experts.

XML Validating Reader problem


From: "R. Raghuraman" <ra********@infosys.com>
Subject: Problem with XMLValidatingReader?
Date: 01 April 2004 11:46

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
Nov 12 '05 #1
2 2599
XmlValidatingReader is a forward only cursor on the underlying Xml. I would
expect the Read() in the catch block to succeed, because it would be reading
the token next to the one that caused the error in your try block.

When you inspect the exception object in the catch block what is the message
you get?

----------------
"Raghu R" <r.***********@ntlworld.com> wrote in message
news:Ad%ac.183$Nc4.129@newsfe1-win...

From: "R. Raghuraman" <ra********@infosys.com>
Subject: Problem with XMLValidatingReader?
Date: 01 April 2004 11:46

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

Nov 12 '05 #2
Hi,
I think I've figured it out - the exceptions I get are of the nature
where the XML is not well formed. MSDN says that XmlTextReader checks for
well-formedness of the document - hence I think that the exception is being
raised by the embedded xmltextreader which is then propogated above. Also,
this bypasses the event handler (but then, in hind sight, it seems obvious)
Code I have works but seems chunky - with the error handling code spread
over two parts....

Thanks!
Raghu
"NaraendiraKumar R. R." <na****@nospam.com> wrote in message
news:Of**************@TK2MSFTNGP10.phx.gbl...
XmlValidatingReader is a forward only cursor on the underlying Xml. I would expect the Read() in the catch block to succeed, because it would be reading the token next to the one that caused the error in your try block.

When you inspect the exception object in the catch block what is the message you get?

----------------
"Raghu R" <r.***********@ntlworld.com> wrote in message
news:Ad%ac.183$Nc4.129@newsfe1-win...

From: "R. Raghuraman" <ra********@infosys.com>
Subject: Problem with XMLValidatingReader?
Date: 01 April 2004 11:46

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


Nov 12 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

6
by: Robert Reineri | last post by:
Hello, New to the XML world and .NET. I have what I believe to be a simple problem, but I have read the .NET docs till I'm blue in the face and still can't locate a simple example of how to...
1
by: Andy | last post by:
I am having some trouble validating XML using the XmlValidatingReader. I have created some xml and used the visual studio to generate the schema. So I am confident that the xml and schema match. ...
2
by: Joris Janssens | last post by:
I'm trying to write a program for validating XHTML 1.1-documents against the XHTML 1.1 DTD (which is actually the same as validating an XML-file) but I always get a "(404) Not found" error. This...
1
by: Brendon | last post by:
I have 2 Xsd's The one contains basic type definitions <?xml version="1.0" encoding="utf-8"?> <xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" elementFormDefault="qualified"...
1
by: Craig Beuker | last post by:
Hello, I am experimenting with this XmlValidatingReader and have a question about how it is working (or not working as would be the case) The sample documents and code are included at the end...
0
by: Jan Eliasen | last post by:
Hi I have programmed a small program in VB.NET to validate an xml-document against an .xsd. You can find my code at the bottom of this posting. My problem is, that if I have an unqualified...
21
by: Darin | last post by:
I have a form w/ a textbox and Cancel button on it. I have a routine to handle textbox.validating, and I have the form setup so the Cancel button is the Cancel button. WHen the user clicks on...
21
by: Jack White | last post by:
Hi there, I've created a strongly-typed "DataSet" using VS. If I save the data via "DataSet.WriteXml()" and later prompt my users for the name of the file in order to read it back in again...
4
by: agda.karlberg | last post by:
Hello, I need to remove the DTD reference from an xml document, the reason for this is that we want to validate against a schema instead (which we have locally). It takes up to a minute to fetch...
0
by: jianzs | last post by:
Introduction Cloud-native applications are conventionally identified as those designed and nurtured on cloud infrastructure. Such applications, rooted in cloud technologies, skillfully benefit from...
0
by: abbasky | last post by:
### Vandf component communication method one: data sharing ​ Vandf components can achieve data exchange through data sharing, state sharing, events, and other methods. Vandf's data exchange method...
2
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 7 Feb 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:30 (7.30PM). In this month's session, the creator of the excellent VBE...
0
by: fareedcanada | last post by:
Hello I am trying to split number on their count. suppose i have 121314151617 (12cnt) then number should be split like 12,13,14,15,16,17 and if 11314151617 (11cnt) then should be split like...
0
Git
by: egorbl4 | last post by:
Скачал я git, хотел начать настройку, а там вылезло вот это Что это? Что мне с этим делать? ...
0
by: DolphinDB | last post by:
The formulas of 101 quantitative trading alphas used by WorldQuant were presented in the paper 101 Formulaic Alphas. However, some formulas are complex, leading to challenges in calculation. Take...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: Aftab Ahmad | last post by:
Hello Experts! I have written a code in MS Access for a cmd called "WhatsApp Message" to open WhatsApp using that very code but the problem is that it gives a popup message everytime I clicked on...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.