0

I am trying to validate a xml file againg a xsd, but for some reason the following Errorr occures. Strange is that different programms, which do the same does not show an error. How can i change the settings for the xsd to not check for missing attributes and just ignore them?

Code:

        static void ValidateXml(string xmlFile, string xsdFile)
        {
            XmlReaderSettings settings = new XmlReaderSettings();
            settings.Schemas.Add(null, xsdFile);
            settings.ValidationType = ValidationType.Schema;
            settings.ValidationEventHandler += ValidationEventHandler;


                using (XmlReader reader = XmlReader.Create(xmlFile, settings)) // failing here
                {
                    while(reader.Read())
                    {
                        // Reading and doing nothing with the xml file.
                    }
                }
            

        }

Error Message:

System.Xml.Schema.XmlSchemaValidationException: "The 'http://www.w3.org/XML/1998/namespace:lang' attribute is not declared."

I tried it using XMlDocument, but that doesnt work for me, cause i am reading of xml files up to 2 gb.

Charles Han
  • 1,920
  • 2
  • 10
  • 19
alexander
  • 1
  • 1
  • Please check if this answer is of help: https://stackoverflow.com/a/48910255/724039 – Luuk Feb 12 '23 at 20:40

0 Answers0