"Die 'http://www.w3.org/XML/1998/namespace:lang' - Attribut nicht deklariert."

Manchmal, wenn die Validierung bestimmter XML-Dokumente über eine XmlValidatingReader, erhalte ich die folgende Fehlermeldung:

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

Gleichen Dokument manchmal gelingt. Ich kann nicht herausfinden, warum.

Mein XSD importiert das schema etwa 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" />
 ...

Und in das XML-Dokument, ich habe die folgenden Attribute:

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

Schließlich die 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()) {}

Dies ist eine standalone-exe-Datei ausgeführt .NET 4.0 auf Windows 2003.

Habe ich bemerkt, dass es eine deutliche pause, wenn es versucht, zu validieren. Könnte das damit zusammenhängen? Wird es versucht, die tatsächliche download "xml.xsd" schema und, nicht erfolgreich zu sein?

InformationsquelleAutor roufamatic | 2011-05-24
Schreibe einen Kommentar