2009-10-16 29 views
1

我想驗證針對其模式定義一個數字簽名的XML,而這個模式實際上包含這個標籤無法驗證針對多個XSD架構在C#

<xs:import namespace="http://www.w3.org/2000/09/xmldsig#" schemaLocation="xmldsig-core-schema.xsd" id="schema"/> 

然後我試圖加載模式:

XmlReaderSettings settings = new XmlReaderSettings(); 
settings.Schemas.Add(null, "a.xsd"); 
settings.Schemas.Compile(); 

我將得到以下錯誤 'http://www.w3.org/2000/09/xmldsig#:Signature'元素未被聲明。

+0

貴XML像XMLSPY工具驗證? 如果我沒有記錯,您應該能夠使用XmlReader對導入/包含模式進行驗證。 – thijs 2009-10-16 09:57:31

回答

2

您需要在導入模式也加載另一個

settings.Schemas.Add([importednamespace][pathtoimportedXSD]);

0

你確定哈希需要在?: http://www.w3.org/2000/09/xmldsig#

+0

它是名稱空間URI的一部分,請參閱http://www.w3.org/TR/2002/REC-xmldsig- core-20020212/xmldsig-core-schema.xsd – Richard 2009-10-16 10:25:57

+0

好的,謝謝,還不知道 – dusoft 2009-10-16 10:35:02

0

末從它似乎XML簽名模式沒有被加載錯誤,儘管進口。

將XML簽名架構顯式添加到架構集應該確認。

最可能的原因是架構集的XmlReslver找不到您指定的文件,這可能是當前文件夾/相對路徑問題。

使用Process Monitor來查看您可以嘗試加載XSD文件的位置也可能有所幫助。

1

出於安全考慮,方案xmldsig-core-schema.xsd不收費,因爲它引用DTD來驗證上傳目錄並將其添加爲另一個方案。

<!DOCTYPE schema PUBLIC "-//W3C//DTD XMLSchema 200102//EN" "http://www.w3.org/2001/XMLSchema.dtd" 

這個作品 的解決方案是C#

XElement xsdMarkup = XElement.Load("C:\\Proyectos\\WindowService\\Sbif\\Schema\\Schema\\IndicadoresFinancieros-v1.0.xsd"); 

XElement xsdMarkup2 = XElement.Load("http://www.w3.org/TR/2002/REC-xmldsig-core-20020212/xmldsig-core-schema.xsd"); 

XmlSchemaSet schemas = new XmlSchemaSet(); 

schemas.Add(null, xsdMarkup.CreateReader()); 
schemas.Add(null, xsdMarkup2.CreateReader()); 

schemas.Compile();