No Validation errors using XDocument.Validate

EDN Admin

Well-known member
Joined
Aug 7, 2010
Messages
12,794
Location
In the Machine
<div style="color:black;background-color:white <br/>Hi, <br/><br/>I am trying to validate an XML file against a set of XSD files but get no errors even when I intentionally change my XML to have errors, like entering text when the XSD declares the type to be numeric, and still it validates correctly. <br/><br/>Anyone has any clues on this?, bellow is my code. <br/><br/>Thanks in advance,<br/>Waldemar<br/><br/>
<pre>Dim errors As Boolean = False

Private Sub XSDErrors(ByVal o As Object, ByVal e As ValidationEventArgs)
Console.WriteLine("{0}", e.Message)
errors = True
End Sub

Sub Main()
Dim xsdMarkup As XElement = XElement.Load("....XSD")
Dim xsdMarkup2 As XElement = XElement.Load("...XSD")


Dim schemas As XmlSchemaSet = New XmlSchemaSet

schemas.Add("...namespace", xsdMarkup.CreateReader)
schemas.Add("...namespace", xsdMarkup2.CreateReader)

Dim doc2 As XDocument
doc2 = XDocument.Load("c:....xml")

doc2.Validate(schemas, AddressOf XSDErrors, True)
Console.WriteLine("doc2 {0}", IIf(errors = True, "did not validate", "validated"))

End Sub[/code]
<br/>

View the full article
 
Back
Top