2010-12-20 61 views
14

這是我運行命令:使用XSD.EXE生成C#文件,收到錯誤和警告

xsd.exe -c -l:c# D:\Documents\DEV\SARPilot\Docs\schemas\06-141r2\06-141r2.xsd 

這是我得到的錯誤:

Microsoft (R) Xml Schemas/DataTypes support utility 
[Microsoft (R) .NET Framework, Version 2.0.50727.3038] 
Copyright (C) Microsoft Corporation. All rights reserved. 
Schema validation warning: Undefined complexType 'http://www.opengis.net/sps/0:ParameterDescriptorType' is used as a base for comp 
lex type extension. Line 617, position 2. 
Schema validation warning: Undefined complexType 'http://www.opengis.net/ows:GetCapabilitiesType' is used as a base for complex ty 
pe extension. Line 23, position 2. 
Schema validation warning: Undefined complexType 'http://www.opengis.net/ows:CapabilitiesBaseType' is used as a base for complex t 
ype extension. Line 35, position 2. 
Schema validation warning: The 'http://www.opengis.net/gml:Point' element is not declared. Line 869, position 2. 
Schema validation warning: The 'http://www.opengis.net/gml:Polygon' element is not declared. Line 870, position 2. 
Schema validation warning: The 'http://www.opengis.net/gml:Rectangle' element is not declared. Line 871, position 2. 
Schema validation warning: The 'http://www.opengis.net/sps/0:Parameter' element is not declared. Line 381, position 2. 
Schema validation warning: The 'http://www.opengis.net/sps/0:ID' element is not declared. Line 451, position 2. 

Warning: Schema could not be validated. Class generation may fail or may produce incorrect results. 

Error: Error generating classes for schema 'D:\Documents\DEV\SARPilot\Docs\schemas\06-141r2\06-141r2'. 
    - The datatype 'http://www.opengis.net/ows:GetCapabilitiesType' is missing. 

If you would like more help, please type "xsd /?". 

C:\Program Files (x86)\Microsoft SDKs\Windows\v7.0A\Bin> 

的XSD文件從附錄A複製/粘貼到以下文檔中: http://services.eoportal.org/portal/documents/06-141r2_Ordering_Services_for_Earth_Observation_Products_0.9.2.pdf

回答

17

包含在您鏈接的PDF文檔中的XML Schema具有對其他幾個XSD文件的引用u唱出<import>元素。您需要下載這些附加架構文件,並確保<import>元素中的路徑引用指向本地計算機上的正確位置。

如果您仍然收到錯誤,這是因爲xsd.exe無法跟進外部引用。爲了解決這個問題,直接在命令行上的所有必需的XSD文件如下:

xsd.exe /c MySchema.xsd Import01.xsd Import02.xsd Include01.xsd Include02.xsd

其中Import01.xsd,Import02.xsd,Include01.xsd和Include02.xsd是通過導入引用XSD文件並在MySchema.xsd中包含元素。

+0

我在本地添加了所有文件,包括那些文件正在調用的文件。但是,同樣的錯誤。我很確定我的問題是錯誤:缺少數據類型'http://www.opengis.net/ows:GetCapabilitiesType'。 – capdragon 2010-12-20 19:07:41

+0

您是否將所有模式添加到相同的文件夾?我看到的'import'語句在不同目錄級別引用了這些附加模式。由於路徑問題,您可能仍然無法找到引用的模式。 – pmartin 2010-12-20 19:38:25

+3

您可以將它們添加到命令行並保持「提示路徑」不變。只要提到每個導入的模式(以及如果再次導入,沖洗和重複)。 xsd.exe/c TopSchema.xsd ImportSchema1.xsd ... ImportOfImportSchema1.xsd – 2010-12-20 19:39:05

23

我有同樣的問題,這是我如何解決它:複製所有XSD針對代碼生成到同一個位置,即引用的XSD文件

1)「C:\項目\ PROJECT1 \文件\ XSD文件\ strucutre」。 2)中提到的所有的提到XSD文件在執行XSD.EXE:

C:\項目\ PROJECT1 \文檔\ XSD文件\ strucutre>「C:\ Program Files文件(x86)的\微軟的SDK \的Windows \ V7。 0A \ BIN \ NETFX 4.0工具\ XSD」 structure.xsd RefXsd1.xsd RefXsd2.xsd RefXsd3.xsd/C/O:C:\項目\ PROJECT1 \文件\ ClassStructure

一個C-尖銳文件,包含在xsds中提到的實體,是在文件夾C:\ Projects \ Project1 \ Documents \ ClassStructure下生成的。

希望這會有所幫助!

+0

謝謝!在過去的幾個小時裏,我一直把頭髮拉出來。我不知道你必須列出所有正在導入/包含在主要xsd中的xsd文件(以及任何導入/包含它們的文件)。 – 2013-12-07 00:23:48

+1

即使我仔細列出所有被引用的.xsd文件,我仍然有這種警告。不知道爲什麼 – Sharif 2017-02-16 16:51:25