"Attribute" http://www.w3.org/XML/1998/namespace:lang "not declared".

Sometimes when checking certain XML documents using XmlValidatingReader, the following error appears:

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

The same document sometimes succeeds. I can’t understand why.

My XSD imports the schema as follows:

 <xs:schema id="myschemaId" xmlns:xs="http://www.w3.org/2001/XMLSchema" targetNamespace="http://mytargetnamespace.com" xmlns="http://mytargetnamespace.com" xmlns:mm="http://mytargetnamespace.com" elementFormDefault="qualified"> <xs:import namespace="http://www.w3.org/XML/1998/namespace" schemaLocation="http://www.w3.org/2001/xml.xsd" /> ... 

And in the XML document, I have the following attributes:

 <root xmlns="http://mytargetnamespace.com" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://mytargetnamespace.com myschema.xsd"> 

Finally, XmlReaderSettings:

 const XmlSchemaValidationFlags validationFlags = XmlSchemaValidationFlags.ProcessInlineSchema | XmlSchemaValidationFlags.ProcessSchemaLocation | XmlSchemaValidationFlags.ReportValidationWarnings | XmlSchemaValidationFlags.AllowXmlAttributes; // Set the validation settings. var settings = new XmlReaderSettings { ValidationType = ValidationType.Schema, ValidationFlags = validationFlags, DtdProcessing = DtdProcessing.Parse }; settings.ValidationEventHandler += OnValidationEventHandler; // Create the XmlReader object. var reader = XmlReader.Create(_xmlFilePath, settings); // Parse the file. while (reader.Read()) {} 

This is a standalone exe running on .NET 4.0 in Windows 2003.

I noticed that there is a significant pause when he tries to check. Could this be related? It tries to load the actual schema "xml.xsd" and does not succeed?

+7
source share
2 answers

Since many of the DTDs and XSDs originated from the W3C, they have a problem that many are trying to eliminate from their servers, as a result of which they are awash with requests - millions and millions of them. Therefore, they began to block "excessive" requests.

See this blog post , which also applies to XSD.

The solution is to use a local copy.

+7
source

I am pretty sure I decided this one. I checked Fiddler and looked at the requests sent to w3c.org for the xsd file. A little more research turned out to be this link ; Remark # 3 seems to be related to my situation. Therefore, if for some reason my machine could not load the XSD file, the xml namespace became inaccessible. Unfortunately, a real error ("failed to reach w3c.org" or what you have) was never reported.

Removing schemaLocation from xs:import did the trick.

+2
source

All Articles