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

15,996

Solution 1

Because many of the DTDs and XSDs originated from the W3C, they have the problem that many people try to resolve them from their servers, resulting in their being inundated with requests - millions and millions of them. So they started blocking "excessive" requests.

See this blog entry, which also applies to XSDs.

The solution is to use a local copy.

Solution 2

I'm pretty confident I've solved this one. I checked Fiddler and did see requests going out to w3c.org for the xsd file. A little more research turned up this link; remark #3 seemed to relate to my situation. So if for whatever reason my machine couldn't download the XSD file, then the xml namespace became unavailable. Sadly the real error ("could not reach w3c.org" or what have you) was never reported.

Removing the schemaLocation from the xs:import did the trick.

Share:
15,996

Related videos on Youtube

roufamatic
Author by

roufamatic

Web and application developer with a strong C# preference, though I enjoy dabbling in other languages and environments. Developer of Web software since 1995 Masters of Software Engineering from Seattle University (awarded 12/2010) Telecommuter FTW!

Updated on June 04, 2022

Comments

  • roufamatic
    roufamatic almost 2 years

    Sometimes, when validating certain XML documents using an XmlValidatingReader, I receive the following error:

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

    The same document sometimes succeeds. I cannot figure out why.

    My XSD imports the schema like so:

    <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, the 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 .NET 4.0 on Windows 2003.

    I've noticed that there's a significant pause when it's trying to validate. Could that be related? Is it trying to download the actual "xml.xsd" schema and not succeeding?

  • Jon Hanna
    Jon Hanna almost 13 years
    You can also set the schemaLocation to a copy of that found on the W3C site (their copyright, but they not only allow this, but very actively encourage it).
  • roufamatic
    roufamatic almost 13 years
    I'm giving you the answer since my customer's toolchain requires the schemaLocation to be present. Thanks, I thought I was going crazy!
  • Sai Ram Reddy
    Sai Ram Reddy over 3 years
    Actually the location is the second parameter of the schemaLocation right ? ``` <xs:import namespace="w3.org/XML/1998/namespace" schemaLocation="w3.org/2001/xml.xsd" /> ``` But there is no second parameter in the above import. Why would it make a call to the w3 site ?