I've blogged about the issues surrounding the XmlSchemaSet class and Open XML schemas before. The ECMA schemas import / include each other heavily, which will cause duplicate schemas to be imported in the XmlSchemaSet class. Now the XmlSchemaSet does support circular imports, but it only does so per distinct call to 'Add', which you use to add a new schema to the set. So if you are going to load schemas using multiple steps, which are likely to do because the Open XML schemas have been split up, you run in to errors.
So this code below will not work correctly for you, and the error will be dependant on the order in which you load schemas.
XmlSchemaSet xs = new XmlSchemaSet();
xs.Add(XmlSchema.Read("wml.xsd"));
xs.Add(XmlSchema.Read("other.xsd"));
To make sure each schema is only present once, you should only call 'Add' once. This of course doesn't load all schemas in memory, because not all schemas import each other. To fix this issue, I've just created an 'All.xsd' file which imports all other Open XML schemas. Because you can now call the XmlSchemaSet.Add method once like you see below, presto! no more errors.
XmlSchemaSet xs = new XmlSchemaSet();
xs.Add(XmlSchema.Read("all.xsd"));
You now know for sure each schema is loaded, and loaded only once. Ready to validate all Open XML files you can throw at it. Get the schema here, or just create your own.
Posted
08-12-2006 11:59
by
Anonymous