views:

55

answers:

1

I've downloaded the official "schema of xsd" from http://www.w3.org/2001/XMLSchema.xsd.

I saved it locally and tried to validate with this code:

var sc = XmlSchema.Read(new FileStream(@"c:\temp\xsd.xsd", FileMode.Open), validate);
sc.Compile(validate);

It failed with an exception that it cannot find some DTD.

Question number 1: Why does the schema of xsd contain definition that xml validators cannot handle?

I removed the DTD definition from the top of the file and I got this (and many more) validation errors:

"Restriction of 'anySimpleType' is not allowed."

Question number 2: Why does compiling the schema of xsd fail?

I've tried the same with XmlSchemaSet using set.Add(...) and it worked.

Question number 3: What is the difference between validating an XmlSchema and XmlSchemaSet?

I then create a dummy schema that imports the xsd schema from disk:

<s:import namespace="http://www.w3.org/2001/XMLSchema" schemaLocation="c:\temp\xsd.xsd" />

When I add this schema to the schema set it fails again with the same errors as above.

Question number 4: Why is that different then directly adding the xsd schema (which worked)?

A: 

You will need a couple of other files referenced by the schema:

XmlSchema.dtd and datatypes.dtd. Once you've downloaded them you can validate:

class Program
{
    static void Main()
    {
        var settings = new XmlReaderSettings();
        settings.ProhibitDtd = false;
        using (var reader = XmlReader.Create("XMLSchema.xsd", settings))
        {
            settings.Schemas.Add(XmlSchema.Read(reader, null));
        }

        using (var reader = XmlReader.Create("xsd.xsd", settings))
        {
            // This will throw if the XML file is not valid
            while (reader.Read()) ;
        }
    }
}
Darin Dimitrov
When I manually removed the DTD declaration it worked when I explicitly added it (as you do). But when I read another document that references it I still get these validation errors on the schema-of-schema itself
Yaron Naveh