Quantcast
Channel: XML, System.Xml, MSXML and XmlLite forum
Viewing all articles
Browse latest Browse all 935

XML Validation with XSD not doing what it's supposed to do

$
0
0

I'm learning XML-validation in C# and I'm stuck. When I run the code I get a validation error: "could not find schema information for the element" for each element I try to read. Any ideas what's wrong?

I have following code

XmlTextReader textReader1 = new XmlTextReader("../../APVDO.xml");
            XmlReaderSettings settings1 = new XmlReaderSettings();
            settings1.ValidationType = ValidationType.Schema;
            settings1.ValidationFlags = XmlSchemaValidationFlags.ReportValidationWarnings;
            settings1.ValidationEventHandler += settings1_ValidationEventHandler;
            settings1.Schemas.Add("http://tempuri.org/APVDO.xsd", "../../APVDO.xsd");

            XmlReader reader1 = XmlReader.Create(textReader1, settings1);

            while (reader1.Read())
            {
                //Console.WriteLine(reader1.Value);
            }

This is the XML document

<?xml version="1.0" ?><personen><docent><voornaam>data</voornaam><familienaam>data</familienaam><geboortedatum>data</geboortedatum><adres><straat>data</straat><nr>data</nr><bus>data</bus><postcode>data</postcode><gemeente>data</gemeente></adres><kinderen><kind><voornaam>data</voornaam><familienaam>data</familienaam><geboortedatum>data</geboortedatum></kind></kinderen></docent><cursist><voornaam>data</voornaam><familienaam>data</familienaam><geboortedatum>data</geboortedatum><adres woontBijOuders="true"><straat>data</straat><nr>data</nr><postcode>data</postcode><gemeente>data</gemeente></adres></cursist>
  ... // more cursist elements</personen>

And the XSD

<?xml version="1.0" encoding="utf-8"?><xs:schema attributeFormDefault="unqualified" elementFormDefault="qualified" xmlns:xs="http://www.w3.org/2001/XMLSchema" targetNamespace="http://tempuri.org/APVDO.xsd" ><xs:element name="personen"><xs:complexType><xs:sequence><xs:element maxOccurs="unbounded" name="docent"><xs:complexType><xs:sequence><xs:element name="voornaam" type="xs:string" /><xs:element name="familienaam" type="xs:string" /><xs:element name="geboortedatum" type="xs:string" /><xs:element name="adres"><xs:complexType><xs:sequence><xs:element name="straat" type="xs:string" /><xs:element name="nr" type="xs:unsignedByte" /><xs:element name="bus" type="xs:unsignedByte" /><xs:element name="postcode" type="xs:unsignedShort" /><xs:element name="gemeente" type="xs:string" /></xs:sequence></xs:complexType></xs:element><xs:element name="kinderen"><xs:complexType><xs:sequence><xs:element name="kind"><xs:complexType><xs:sequence><xs:element name="voornaam" type="xs:string" /><xs:element name="familienaam" type="xs:string" /><xs:element name="geboortedatum" type="xs:string" /></xs:sequence></xs:complexType></xs:element></xs:sequence></xs:complexType></xs:element></xs:sequence></xs:complexType></xs:element><xs:element maxOccurs="unbounded" name="cursist"><xs:complexType><xs:sequence><xs:element name="voornaam" type="xs:string" /><xs:element name="familienaam" type="xs:string" /><xs:element name="geboortedatum" type="xs:date" /><xs:element name="adres"><xs:complexType><xs:sequence><xs:element name="straat" type="xs:string" /><xs:element name="nr" type="xs:unsignedByte" /><xs:element minOccurs="0" name="bus" type="xs:unsignedByte" /><xs:element name="postcode" type="xs:unsignedShort" /><xs:element name="gemeente" type="xs:string" /></xs:sequence><xs:attribute name="woontBijOuders" type="xs:boolean" use="optional" /></xs:complexType></xs:element></xs:sequence></xs:complexType></xs:element></xs:sequence></xs:complexType></xs:element></xs:schema>


Viewing all articles
Browse latest Browse all 935

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>