MaxMax wrote:
If I have an XmlDocument and I want to discover which namespaces it has, how
should I do? And is the schemaLocation attribute automatically expanded
somewhere? (the schemaLocation has this format:
namespacename filename [namespacename filename] [namespacename filename]
... )
I want to validate the XML file to its namespaces, but if I can't find which
namespaces it has, how should I do?
(and I need the name of the various namespaces for other reasons).
If you want to validate against the schemas listed in the schemaLocation
attribute then you need to use XmlReaderSettings with the
ValidationFlags set to include ProcessSchemaLocation so like this
XmlReaderSettings readerSettings = new XmlReaderSettings();
readerSettings.ValdiationFlags |=
XmlSchemaValidationFlags.ProcessSchemaLocation;
readerSettings.ValidationEventHandler += delegate (object sender,
ValdiationEventArgs vargs) {
// handle validation errors here
}
using (XmlReader xmlReader = XmlReader.Create(@"file.xml",
readerSettings)) {
while (xmlReader.Read()) {}
}
--
Martin Honnen --- MVP XML
http://JavaScript.FAQTs.com/