“La 'http://www.w3.org/XML/1998/namespace:lang' attribut n'est pas déclaré.”

Parfois, lors de la validation de certains documents XML à l'aide d'un XmlValidatingReader, je reçois l'erreur suivante:

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

Le même document parfois réussit. Je ne peux pas comprendre pourquoi.

Mon XSD importe le schéma comme suit:

<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" />
 ...

Et dans le document XML je avoir les attributs suivants:

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

Enfin, la 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()) {}

C'est un exe autonome d'exécution .NET 4.0 sur Windows 2003.

J'ai remarqué qu'il y a un arrêt important lorsque l'on cherche à valider. Pourrait-il être lié? Est-il en essayant de télécharger le réel "xml.xsd schéma" et de ne pas réussir?

OriginalL'auteur roufamatic | 2011-05-24