gpt4 book ai didi

c# - 将 XSD 文件转换为 C# 可序列化类

转载 作者:数据小太阳 更新时间:2023-10-29 02:49:33 25 4
gpt4 key购买 nike

我尝试按照 this question 的答案进行操作, 但无法让 xsd.exe 愉快地获取 XSD 文件并将它们变成一个类。

在这里使用 XSD 文件:http://download.adamhaile.com/SO/XSD.zip
任何人都可以帮助我将这些转换为有效的 C# 类,然后可以将其用于序列化 XML 文档吗?

注意:是的,这些来 self 尝试使用的未记录的 Yahoo Movies API。看起来它使用的是基于 Microsoft 的标准模式模式,所以我认为这是很有可能的。

以下是其中一个 API 调用的结果示例: http://new.api.movies.yahoo.com/v2/listTheatersByPostalCode?pcode=12345&count=30&yprop=msapi

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

最佳答案

请务必将所有引用的模式放在 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 手动解决该问题。或者,如果您不关心便利设施部分,请放弃它。

关于c# - 将 XSD 文件转换为 C# 可序列化类,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1060017/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com