Donal McWeeney wrote:
Schemas is empty and only used (I think) for the purposes of validation.
I want to do two things:
- dynamically determine what schemas are referenced in a document so I can
build a XmlSchemaSet with the correct file paths to the actual schema files
for validating the document.
So currently you simply load an XML document into an XmlDocument object
but you want to validate while loading using the xsi:schemaLocat ion (or
xsi:noNamespace SchemaLocaton) hints in the document?
Then you need to use an XmlReader with the proper settings e.g.
XmlReaderSettin gs readerSettings = new XmlReaderSettin gs();
readerSettings. ValidationType = ValidationType. Schema;
readerSettings. ValidationFlags |=
XmlSchemaValida tionFlags.Proce ssSchemaLocatio n;
readerSettings. ValidationEvent Handler += new
ValidationEvent Handler(Validat ionHandler);
XmlDocument xmlDocument = new XmlDocument();
xmlDocument.Loa d(XmlReader.Cre ate(@"file.xml" , readerSettings) );
// now Schemas is a filled XmlSchemaSet
Console.WriteLi ne(xmlDocument. Schemas.Count);
I don't think there is any need to look for the schemas yourself, the
framework does that automatically if you use the proper settings as
shown above.
--
Martin Honnen --- MVP XML
http://JavaScript.FAQTs.com/