I don't have the full version of VS so I'm not sure if there is some "automatically validate against schema" setting in the IDE when you create an XML file maybe?
Anyway, so for validation, you can do something like this perhaps:
vb.net Code:
' Check my Xml. Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click ' Setup the settings. Dim rdrSets As New XmlReaderSettings() With rdrSets .ValidationType = ValidationType.Schema .ValidationFlags = XmlSchemaValidationFlags.ProcessInlineSchema Or _ XmlSchemaValidationFlags.ProcessSchemaLocation Or _ XmlSchemaValidationFlags.ReportValidationWarnings End With ' Validation event handler. AddHandler rdrSets.ValidationEventHandler, AddressOf ValidateXML Dim rdr As XmlReader = XmlReader.Create("C:\simple.xml", rdrSets) ' Read the XML file. Do While rdr.Read() Loop End Sub Private Sub ValidateXML(ByVal sender As Object, ByVal e As ValidationEventArgs) ' <bad> is not a good node. MessageBox.Show("Error in validation: " & e.Message) End Sub




Reply With Quote