2009-06-29 45 views
2

我嘗試了this question的回答,但無法讓xsd.exe愉快地將XSD文件轉換爲類。將XSD文件轉換爲C#可序列化類

使用XSD文件在這裏:http://download.adamhaile.com/SO/XSD.zip
誰能幫我將這些來,然後可以使用序列化的XML文檔有效的C#類?

注:是的,這些來自我正在嘗試使用的無證雅虎電影API。它看起來像是使用標準的基於Microsoft的架構模式,所以我會想象這很有可能。

下面是從API調用的一個結果的例子: http://new.api.movies.yahoo.com/v2/listTheatersByPostalCode?pcode=12345&count=30&yprop=msapi

http://download.adamhaile.com/SO/XSD.zip

回答

4

確保將所有引用的模式放在cmd行上。
當我這樣做時,我收到了一堆警告。

$ xsd /c listTheatersByPostalCode.xsd yahooMovie.xsd yahooMovieCredit.xsd yahooMovieMedia.xsd yahooMoviePhoto.xsd yahooMovieTheater.xsd yahooMovieTheaterAmenity.xsd yahooMultimedia.xsd yahooUser.xsd 
Microsoft (R) Xml Schemas/DataTypes support utility 
[Microsoft (R) .NET Framework, Version 2.0.50727.42] 
Copyright (C) Microsoft Corporation. All rights reserved. 
Schema validation warning: The global element 'urn:yahoo:movie:theater:TheaterList' has already been declared. Line 6, position 4. 
Schema validation warning: The global attribute 'urn:yahoo:movie:theater:id' has already been declared. Line 7, position 4. 
Schema validation warning: The complexType 'urn:yahoo:movie:theater:TheaterListType' has already been declared. Line 10, position 4. 
Schema validation warning: The complexType 'urn:yahoo:movie:theater:TheaterType' has already been declared. Line 19, position 4. 
Schema validation warning: The complexType 'urn:yahoo:movie:theater:PostalAddressType' has already been declared. Line 32, position 4. 
Schema validation warning: The complexType 'urn:yahoo:movie:theater:AmenityListType' has already been declared. Line 55, position 4. 
Schema validation warning: The complexType 'urn:yahoo:movie:theater:MovieListType' has already been declared. Line 65, position 4. 
Schema validation warning: The complexType 'urn:yahoo:movie:theater:MovieType' has already been declared. Line 71, position 4. 
Schema validation warning: The complexType 'urn:yahoo:movie:theater:ShowsType' has already been declared. Line 82, position 4. 

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

如果我從該列表中取出yahooTheater.xsd,它工作正常。

我甚至沒有看XSD,但在我看來,xsd.exe認爲一些元素已被雙重定義。您可以通過將yahootheater.xsd與yahooTheaterAmenity.xsd結合來手動協調該問題。或者,如果您不關心舒適環境,請放棄它。

+0

所以,拿出那個文件最終給了我相同的確切.cs文件,它只是不會拋出這些錯誤......怪異...... 雖然,所有類的部分處理是什麼? – 2009-06-30 04:29:10

+0

呵呵? 「取出文件結束」?至於部分課程,如果你喜歡,你可以擴展它們。他們*可能*部分。他們將編譯沒有mods和沒有進一步的代碼。 – Cheeso 2009-06-30 12:49:25

2

使用隨Visual Studio中的XSD.EXE。 iirc xsd/classes theschema.xsd

但是既然你試過了,出了什麼問題?

+0

它只吐出一個部分類,但沒有奏效,並表示模式無法驗證。 – 2009-06-29 19:26:57

1

如何給CodeXS一個嘗試?他們通常對我來說工作得很好。