我試圖驗證對命名MedisinskeOpplysninger-v1.5.xsd從這個集合的模式的XML文檔:http://www.kith.no/upload/1611/v1.5/PLO-schema%20v1.5.zip爲什麼.NET模式驗證聲稱名稱空間lang屬性未聲明?
基本上,我引用的架構添加到C#中的SchemaSet,並通過指定SchemaSet驗證我的XML到XmlReaderSettings的相應屬性並運行XmlReader。
我收到以下錯誤信息:
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()
我小提琴手看到.NET正試圖從w3c.org下載xml.xsd,但失敗(服務器以504響應),所以我試圖下載xml.xsd並將其明確包含在我的SchemaSet中。當我嘗試這個時,.NET聲稱
The global attribute 'http://www.w3.org/XML/1998/namespace:lang' has already been declared.
我很困惑。有任何想法嗎?
我在.NET 3.5,C#,Visual Studio 2010中,Windows 7的
更新
我試圖按照意見伊恩的建議,並從LonData添加的自定義解析器。我可以通過觀察Fiddler跟蹤來看到它確實有效,因爲現在不會嘗試解析來自外部地址的模式。
我現在收到以下錯誤消息: 未聲明'http://www.w3.org/2000/09/xmldsig#:Signature'元素。
我的XML目錄文件看起來像這樣:
<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>
這個答案對你有幫助嗎? http://stackoverflow.com/questions/3449180/using-net-to-validate-xml-against-a-schema – Ian 2012-01-05 13:15:35
@我不是真的,我已經用結果更新了問題。 – Eyvind 2012-01-12 14:52:28