Validation against XSD with different namespace

EDN Admin

Well-known member
Joined
Aug 7, 2010
Messages
12,794
Location
In the Machine
I have an XML file and an XSD file that may have the wrong namespace if someone has put the wrong version in the validation folder. When the file is the correct version, then the validator works fine, and lists all errors in the XML, but when wrong,
just reports the XML as valid.
Im using the following code..
<pre class="prettyprint lang-vb Dim errors As Boolean = False
Dim FullErrors As String = ""
Private Sub XSDErrors(ByVal o As Object, ByVal e As ValidationEventArgs)
FullErrors += Regex.Replace(e.Message, "http:.*:", "") + Environment.NewLine
errors = True
End Sub

Private Sub btnValidateXML_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnValidateXML.Click
Dim schemas As XmlSchemaSet = New XmlSchemaSet()
Dim XMLDoc As New XDocument()

Try
XMLDoc = XDocument.Parse(txtXML.Text)
Catch ex As Exception
txtXMLErrors.Text = "This is not a well formed XML document"
Return
End Try
schemas.Add(Nothing, "exb.xsd")

errors = False
FullErrors = ""
XMLDoc.Validate(schemas, AddressOf XSDErrors)

If errors Then
txtXMLErrors.Text = FullErrors
Else
txtXMLErrors.Text = "Validation Successful"
End If
End Sub
[/code]
How can you check that the namespace of the XML and XSD documents match before doing the validation?


View the full article
 
Back
Top