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:schemaLocation (or
xsi:noNamespaceSchemaLocaton) hints in the document?
Then you need to use an XmlReader with the proper settings e.g.
XmlReaderSettings readerSettings = new XmlReaderSettings();
readerSettings.ValidationType = ValidationType.Schema;
readerSettings.ValidationFlags |=
XmlSchemaValidationFlags.ProcessSchemaLocation;
readerSettings.ValidationEventHandler += new
ValidationEventHandler(ValidationHandler);
XmlDocument xmlDocument = new XmlDocument();
xmlDocument.Load(XmlReader.Create(@"file.xml", readerSettings));
// now Schemas is a filled XmlSchemaSet
Console.WriteLine(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/