I'm trying to validate an XmlDocument with an XSD schema,
and I'm getting the following error:
Could not find schema information for the
element 'month'. An error occurred at , (1, 40).
Here is the code I'm using for validation:
System.Text.UTF8Encoding utf8 = new
System.Text.UTF8Encoding(false);
XmlTextReader xr = null;
XmlValidatingReader vr = null;
xr = new XmlTextReader(Server.MapPath
("progressoverview.xsd"));
vr = new XmlValidatingReader(xr);
System.Xml.Schema.ValidationEventHandler schemaval = new
System.Xml.Schema.ValidationEventHandler
(this.val_ValidationEventHandler);
System.Xml.Schema.XmlSchema sch =
System.Xml.Schema.XmlSchema.Read(vr, schemaval);
sch.Compile(schemaval);
System.IO.MemoryStream mem = new System.IO.MemoryStream
(utf8.GetBytes(doc.OuterXml));
System.Xml.XmlTextReader rdr = new XmlTextReader(mem);
System.Xml.XmlValidatingReader val = new
XmlValidatingReader(rdr);
val.Schemas.Add(sch);
val.ValidationType = ValidationType.Schema;
val.ValidationEventHandler += schemaval;
while(val.Read())
{
System.Diagnostics.Debug.WriteLine(val.Name);
}
private void val_ValidationEventHandler(object sender,
System.Xml.Schema.ValidationEventArgs e)
{
System.Diagnostics.Debug.WriteLine(e.Message);
}
-----
Here is my XML:
<?xml version="1.0" encoding="utf-8" ?>
<month number="1" type="month">
<week id="1">
</week>
</month>
-----
Here is my XSD:
<?xml version="1.0" encoding="utf-8" ?>
<xs:schema id="progressoverview"
targetNamespace="http://tempuri.org/progressoverview.xsd"
elementFormDefault="qualified"
xmlns="http://tempuri.org/progressoverview.xsd"
xmlns:xs="http://www.w3.org/2001/XMLSchema">
<xs:element name="month">
<xs:complexType>
<xs:sequence>
<xs:element name="week" minOccurs="1"
maxOccurs="4">
<xs:complexType>
<xs:sequence>
<xs:element name="day"
minOccurs="1" maxOccurs="7">
<xs:complexType>
<xs:attribute
name="id" type="xs:positiveInteger" />
<xs:attribute
name="status" type="xs:string" />
</xs:complexType>
</xs:element>
</xs:sequence>
<xs:attribute name="id"
type="xs:positiveInteger" />
</xs:complexType>
</xs:element>
</xs:sequence>
<xs:attribute name="number"
type="xs:positiveInteger" />
<xs:attribute name="type" type="xs:string" />
</xs:complexType>
</xs:element>
</xs:schema>
-----
Any info on this would be most helpful...thanks!
Jonas