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