Validate XML

jamie_pattison

Well-known member
Joined
Sep 9, 2008
Messages
116
Programming Experience
Beginner
I have an XSD file which i would like to validated when an XML file is produced. How/Where could i start with this? Any links or videos? Im not entirely sure about XML other than some terminology used here and there so help on this would be good too.

Thanks
 
Thanks that helps but since im not an expert with XML i dont understand if i need the parameter ByVal xmlns As String for any reason? This is causing the error but then again i could be doing something wrong.

Currently the first line of the XML is <cc:Company xmlns:cc="urn:New-distribution:2003-06-30" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="urn:New-distribution:2003-06-30 C:\Test.xsd">

the error i receive when running the code is "The urn:New-distribution:2003-06-30:Company" element is not declared.

Thanks
 
Hmmm, try this code and see if you get different results.

VB.NET:
	Private Sub XmlValidationEventHandler(ByVal sender As Object, ByVal e As ValidationEventArgs)
		Debug.WriteLine(e.Message)
	End Sub

	Private Sub ValidateXml(ByVal xmlDocument As String, ByVal xsdDocument As String)

		Dim xmlDoc As New XmlDocument
		xmlDoc.Load(xmlDocument)
		xmlDoc.Schemas.Add(Nothing, xsdDocument)

		Dim validationHandler As ValidationEventHandler = New ValidationEventHandler(AddressOf XmlValidationEventHandler)
		xmlDoc.Validate(validationHandler)

	End Sub
 
Back
Top