2

I try to validate an XML document against the schema named MedisinskeOpplysninger-v1.5.xsd from this collection: http://www.kith.no/upload/1611/v1.5/PLO-schema%20v1.5.zip

Basically, I add the referenced schemas to a SchemaSet in C#, and validate my XML by assigning the SchemaSet to the corresponding property of the XmlReaderSettings and run an XmlReader.

I get the following error message:

System.Xml.Schema.XmlSchemaException : The 'http://www.w3.org/XML/1998/namespace:lang' attribute is not declared.
    at System.Xml.Schema.XmlSchemaSet.InternalValidationCallback(Object sender, ValidationEventArgs e)
    at System.Xml.Schema.BaseProcessor.SendValidationEvent(XmlSchemaException e, XmlSeverityType severity)
    at System.Xml.Schema.BaseProcessor.SendValidationEvent(XmlSchemaException e)
    at System.Xml.Schema.Compiler.CompileElement(XmlSchemaElement xe)
    at System.Xml.Schema.Compiler.Compile()
    at System.Xml.Schema.Compiler.Execute(XmlSchemaSet schemaSet, SchemaInfo schemaCompiledInfo)
    at System.Xml.Schema.XmlSchemaSet.Compile()

I see in Fiddler that .NET is trying to download xml.xsd from w3c.org, but fails (the server responds with a 504), so I have tried to download xml.xsd and include it explicitly in my SchemaSet. When I try this, .NET claims that

The global attribute 'http://www.w3.org/XML/1998/namespace:lang' has already been declared. 

I am confused. Any ideas?

I'm on .NET 3.5, C#, Visual Studio 2010, Windows 7.

Update

I have tried Ian's suggestion per the comments, and added the custom resolver from LonData. I can see by watching the Fiddler trace that it is indeed in effect, since no attempt to resolve schemas from external addresses happens now.

I now get the following error message: The 'http://www.w3.org/2000/09/xmldsig#:Signature' element is not declared.

My XML catalog file looks like this:

<catalog xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="urn:oasis:names:tc:entity:xmlns:xml:catalog">
   <systemSuffix systemIdSuffix="XMLSchema.xsd" uri="C:\Users\eax\AppData\Local\Temp\XMLSchema.xsd"/>
   <systemSuffix systemIdSuffix="datatypes.dtd" uri="C:\Users\eax\AppData\Local\Temp\datatypes.dtd"/>
   <systemSuffix systemIdSuffix="XMLSchema.dtd" uri="C:\Users\eax\AppData\Local\Temp\XMLSchema.dtd"/>
   <systemSuffix systemIdSuffix="Xmldsig.xsd" uri="C:\Users\eax\AppData\Local\Temp\Xmldsig.xsd"/>
   <systemSuffix systemIdSuffix="xmldsig-core-schema.xsd" uri="C:\Users\eax\AppData\Local\Temp\xmldsig-core-schema.xsd"/>
   <systemSuffix systemIdSuffix="xml.xsd" uri="C:\Users\eax\AppData\Local\Temp\xml.xsd"/>
   <systemSuffix systemIdSuffix="xhtml1-strict.xsd" uri="C:\Users\eax\AppData\Local\Temp\xhtml1-strict.xsd"/>
</catalog>
Eyvind
  • 5,221
  • 5
  • 40
  • 59
  • Does this answer help you...? http://stackoverflow.com/questions/3449180/using-net-to-validate-xml-against-a-schema – Ian Jan 05 '12 at 13:15
  • @Ian not really, I've updated the questions with the results. – Eyvind Jan 12 '12 at 14:52

1 Answers1

1

Just dealt with the same issue for a couple of days and i found that adding schema to the SchemaSet directly raises a problem. So you have to add that schema using XmlReader and with DtdProcessing = Ignore setttings.

Also if you provide your validation related code it would be easier to provide an exact answer.

By the way check this answer also:

Ahmet
  • 1,045
  • 13
  • 28