我尝试按照this question的答案,但无法让xsd.exe高兴地获取XSD文件并将其转换为类。
在此处使用XSD文件:http://download.adamhaile.com/SO/XSD.zip
任何人都可以帮助我将这些转换为有效的C#类,然后可以将其用于序列化XML文档吗?
注意:是的,这些来自我正在尝试使用的未记录的Yahoo Movies API。它看起来像是使用标准的基于Microsoft的架构模式,所以我想这很有可能。
以下是其中一个API调用的结果示例: http://new.api.movies.yahoo.com/v2/listTheatersByPostalCode?pcode=12345&count=30&yprop=msapi
答案 0 :(得分: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相结合来手动协调该问题。或者,如果您不关心舒适性部分,请将其丢弃。
答案 1 :(得分:2)
使用visual studio附带的xsd.exe。 iirc xsd / classes theschema.xsd
但既然你试过了,出了什么问题?
答案 2 :(得分:2)
试试http://www.altova.com/download.html。它有30天的试用期,但它会将xml xsd转换为类。它还反向工程师xml来制作一个xsd。
答案 3 :(得分:1)
试试CodeXS怎么样?他们通常对我很好。