473,385 Members | 1,766 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,385 software developers and data experts.

XML reader not validating

I have written folowing code for xml validation but it is not giving any errors for missing fields.
Even if the XML is in wrong format no error is thrown.

Here is the code...
Public Function validatexml(ByVal xml As String, ByVal operation As Integer) As Integer

Dim aTextReader As TextReader
aTextReader = New StringReader(xml)
Dim txtReader = XmlTextReader.Create(aTextReader)

bTextReader = New StreamReader("C:\\Schema\AddRequest.xsd")
Dim sc As New XmlSchema()
Dim schemareader As XmlReader = XmlReader.Create(bTextReader, Nothing)
sc = XmlSchema.Read(schemareader, AddressOf ValidationCallBack)

caseTextReader = New StreamReader("c:\\Schema\CaseRequest.xsd")
Dim caseSc As New XmlSchema()
Dim caseSchemareader As XmlReader = XmlReader.Create(caseTextReader)
caseSc = XmlSchema.Read(caseSchemareader, AddressOf ValidationCallBack)
caseSc.Parent = sc

Dim settings As New XmlReaderSettings()
settings.ValidationType = ValidationType.Schema settings.IgnoreWhitespace = True
settings.ValidationFlags = XmlSchemaValidationFlags.ProcessInlineSchema
settings.ValidationFlags = XmlSchemaValidationFlags.AllowXmlAttributes
settings.NameTable = New System.Xml.NameTable()

settings.Schemas.Add(sc)
settings.Schemas.Add(caseSc)

AddHandler settings.ValidationEventHandler, AddressOf ValidationCallBack

Dim Reader As XmlReader = XmlReader.Create(txtReader, settings)
While Reader.Read()
Reader.Name.ToString()
End While
End Function

Private Sub ValidationCallBack(ByVal sender As Object, ByVal args As ValidationEventArgs)
'catch the error messages and count
p_Success = p_Success + 1
End Sub
Aug 22 '08 #1
1 2072
saudamini bhadange wrote:
I have written folowing code for xml validation but it is not giving any errors for missing fields.
Even if the XML is in wrong format no error is thrown.
You have set up a ValidationEventHandler thus any validation failure
will not result in error being thrown but rather in calling that
handler. As that handler does not output anything but simply increments
a variable I am not surprised that you don't see any errors. You need to
output args.Message in the handler.

If you still have problems then we need to see your XML and the schema(s).


--

Martin Honnen --- MVP XML
http://JavaScript.FAQTs.com/
Aug 23 '08 #2

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

Similar topics

2
by: Raghu R | last post by:
From: "R. Raghuraman" <raghuraman@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...
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...
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: 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...
1
by: Stefano Sbrulli | last post by:
I am trying to use a validating reader to open an xml file with an associated DTD specifying all the entities I need. This method should work for entire files, but I get the error line "reference...
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...
2
by: mortb | last post by:
Why is line number and position = 0 in the code below? Valiation errors are found but not their position. cheers, mortb public static void Main() { XmlDocument xml = new XmlDocument();...
5
by: William Johnston | last post by:
Hello, I get the following error when instanciating an XmlReader that performs validation: "The 'http://tenbase2.com/DVDTimestamps:schemaLocation' attribute is not declared." My beginning...
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: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...

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.