1 Attachment(s)
XSD: How do schemas point out errors?
I have edited simple.xml slightly and added another element (called "bad") that should result in the document being invalid. Yet the schema does not pick up on this.
I was using Internet Explorer 7 to read the xml file. Any help would be good :)
Contents of Simple.xsd (the schema):
Code:
<?xml version = "1.0" encoding = "UTF-8"?>
<!--Generated by XML Authority. Conforms to w3c http://www.w3.org/2001/XMLSchema-->
<xsd:schema xmlns:xsd = "http://www.w3.org/2001/XMLSchema">
<xsd:element name = "vehicles">
<xsd:complexType>
<xsd:sequence>
<xsd:element name = "nickname" type = "xsd:string" maxOccurs = "unbounded"/>
</xsd:sequence>
</xsd:complexType>
</xsd:element>
</xsd:schema>
Re: XSD: How do schemas point out errors?
But it isn't valid. Check this out:
http://tools.decisionsoft.com/schemaValidate/
cvc-complex-type.2.4.a: Invalid content was found starting with element 'bad'. One of '{"":nickname}' is expected.
Re: XSD: How do schemas point out errors?
So you would need an XML validator....
That answers a few questions
Re: XSD: How do schemas point out errors?
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