2016-07-29 543 views
1

我是xsds的新手,目前我正在使用的xsd只能在某些機器上驗證。它適用於我的本地機器,但是當我嘗試在有代理或防火牆的機器上執行此操作時,它不再有效。雖然我使用的模式在本地使用。xsd在某些系統上無法驗證:「無法將名稱解析爲(n)'類型定義'組件。」

下面是當XSD架構試圖驗證我的錯誤:

SRC-決心:無法解析名稱「xenc:EncryptedDataType」的(N) 「類型定義」的組成部分。

它來源於此代碼:

boolean validate(URL schemaUrl) { 
     SchemaFactory schemaFactory = SchemaFactory 
       .newInstance("http://www.w3.org/2001/XMLSchema"); 
     Schema schema = null; 
     try { 
      schema = schemaFactory.newSchema(schemaUrl); //this is where the exception is thrown 
     } catch (SAXException e) { 
      //exception is caught here 
      return false; 
     } 
     //... more code here 
} 

誤差具有相同的堆棧跟蹤,因爲這一個: SAXParseException; src-resolve: Cannot resolve the name '...' to a(n) 'type definition' component

我有我的主要XSD開頭是這樣的:

<?xml version="1.0" encoding="utf-8" ?> 
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" 
      xmlns:xenc="http://www.w3.org/2001/04/xmlenc#" 
      xmlns:ds="http://www.w3.org/2000/09/xmldsig#" 
      xmlns:tns="http://customization.elster.com/shipment" 
      targetNamespace="http://customization.client.com/introduction" 
      attributeFormDefault="unqualified" 
      elementFormDefault="qualified" 
      version="1.1" > 
    <xs:import namespace="http://www.w3.org/2001/04/xmlenc#" schemaLocation="xenc-schema.xsd"/> 
<xs:import namespace="http://www.w3.org/2000/09/xmldsig#" schemaLocation="xmldsig-core-schema.xsd"/> 

這個主要的XML我n EED的 「xenc:EncryptedDataType」

<xs:complexType name="NamedEncryptedDataType"> 
     <xs:complexContent> 
      <xs:extension base="xenc:EncryptedDataType"> 
       <xs:attribute name="name" type="xs:string" use="required"/> 
      </xs:extension> 
     </xs:complexContent> 
    </xs:complexType> 

其在xenc-schema.xsd(這是在同一文件夾作爲我的主要XSD)定義

<?xml version="1.0" encoding="utf-8"?> 
<!DOCTYPE schema PUBLIC "-//W3C//DTD XMLSchema 200102//EN" 
"http://www.w3.org/2001/XMLSchema.dtd" 
[ 
<!ATTLIST schema 
    xmlns:xenc CDATA #FIXED 'http://www.w3.org/2001/04/xmlenc#' 
    xmlns:ds CDATA #FIXED 'http://www.w3.org/2000/09/xmldsig#'> 
    <!ENTITY xenc 'http://www.w3.org/2001/04/xmlenc#'> 
    <!ENTITY % p ''> 
    <!ENTITY % s ''> 
    ]> 

<schema xmlns='http://www.w3.org/2001/XMLSchema' version='1.0' 
     xmlns:xenc='http://www.w3.org/2001/04/xmlenc#' 
     xmlns:ds='http://www.w3.org/2000/09/xmldsig#' 
     targetNamespace='http://www.w3.org/2001/04/xmlenc#' 
     elementFormDefault='qualified'> 

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

在該xenc型模式,還有就是罪魁禍首數據類型:

<element name='EncryptedData' type='xenc:EncryptedDataType'/> 
    <complexType name='EncryptedDataType'> 
    <complexContent> 
     <extension base='xenc:EncryptedType'> 
     </extension> 
    </complexContent> 
    </complexType> 

我試圖讓這個問題更短,讓我知道,如果需要更多的信息,感謝您的閱讀。

回答

1

診斷這類問題的最佳方法是安裝HTTP調試器。例如,Fiddler是一個適合你的好工具。它應該告訴你哪些資源是在外部(在Internet上)解決的。

就你而言,最有可能的罪魁禍首是你的xenc-schema.xsd文件中的DTD。要快速證明它,只需刪除任何嵌入的DTD。一旦你證明了這個問題,你可以選擇簡單地保留編輯好的XSD,或者使用一個自定義的EntityResolver,或者查看你的特定庫是否有某種你可以設置禁用DTD處理的屬性(這裏真的沒用)。

+0

似乎完全刪除DOCTYPE,與DTD做了伎倆。感謝您的建議。 –

+0

@VladIlie,我想我看到了一個較早的評論:沒有看到任何外部流量。只是爲了確保,對於Java應用程序,您需要配置您的代理信息 - 此[鏈接](http://docs.telerik.com/fiddler/Configure-Fiddler/Tasks/ConfigureJavaApp)可能會有幫助。 –

+0

你是對的,謝謝@PetruGardea –

相關問題