XmlReaderSettings does not resolve an xs:import with http://... location
-
Hi, I'm trying to validate an Xml document using an XmlReader. Here is my code: private void Validate(TextReader source, string xsd) { XmlReaderSettings settings = new XmlReaderSettings(); XmlUrlResolver resolver = new XmlUrlResolver(); settings.ProhibitDtd = false; resolver.Credentials = CredentialCache.DefaultCredentials; settings.XmlResolver = resolver; settings.ValidationFlags = XmlSchemaValidationFlags.ProcessSchemaLocation; settings.ValidationFlags |= XmlSchemaValidationFlags.ReportValidationWarnings; settings.Schemas.XmlResolver = resolver; settings.Schemas.Add(null, xsd); settings.Schemas.Compile(); \\settings.Schemas.Add(null, http://www.w3.org/2001/xml.xsd); settings.ValidationType = ValidationType.Schema; settings.ValidationEventHandler += ValidationHandler; XmlReader reader = XmlReader.Create(source, settings); while (reader.Read()) { } } The xsd of the xml document I want to validate contains an xs:import that points to local xsd (the schemaLocation is, as example "./dc.xsd"). This xsd imports serveral other xsd, one of which is the following: When settings.Schemas.Add(null,xsd) is executed, all nested LOCAL xsd are correctly resolved by the XmlUrlResolver I created. If i inspect during debug my XmlReaderSetting instance i can see tha all the required xsd are correctly loaded, EXCEPT http://www.w3.org/2001/03/xml.xsd. Then settings.Schemas.Compile() is executed, an exception is raised telling me that the attribute xml:lang is not defined (it's defined in the missing xsd). This exception is not raised, and validaion is performed correctly, if i manually add the namespace (see the commented line of my code), or if i change the scema location in the xsd file to point to a local copy of xml.xsd (schemaLocation="./xml.xsd"). I would like to know how can I make this work, because i don't want to add manually anything related to this specific scenario (i.e. i would like to reuse the code). In other words, why this remote location is not resolved?