' First create Xml document
Dim oXmlDocument As New System.Xml.XmlDocument
oXmlDocument.LoadXml("<Trees><Oak TreeType=""deciduous""></Oak></Trees>")
oXmlDocument.Save("Trees.xml")
' .NET save xml document with spaces
<Trees>
<Oak TreeType=""deciduous"">
</Oak>
</Trees>
' Because there is spaces between <Oak ...and </Oakvalidation against an
xsd schema will now fail. Complains about white space.
' However, if the endelemnt </Oakwas removed and we closed the orginal Oak
like this:
<Trees>
<Oak TreeType=""deciduous""/>
</Trees>
' Validation succeeds. How can this be??
' validation code
Dim oXMLReader As Xml.XmlTextReader
Dim oXMLDoc As Xml.XmlDocument
Dim oXMLValidate As Xml.XmlValidatingReader
oXMLReader = New Xml.XmlTextReader("Trees.xml")
oXMLValidate = New Xml.XmlValidatingReader(oXMLReader)
oXMLValidate.ValidationType = Xml.ValidationType.Schema
dim oSchemaCollection As System.Xml.Schema.XmlSchemaCollection
oSchemaCollection = New System.Xml.Schema.XmlSchemaCollection
oSchemaCollection.Add(Nothing, "Trees.xsd") ' get .Net to autogenerate
oXMLValidate.Schemas.Add(oSchemaCollection)
oXMLDoc = New Xml.XmlDocument
oXMLDoc.Load(oXMLValidate)