3

我正在从 OTA(开放旅游联盟)XSD 文件生成 C# 类。您可以从这里下载 XSD 文件

我在 Visual Studio 命令提示符中使用以下命令创建 C# 类:

xsd FS_OTA_VehLocDetailsNotifRQ.xsd /classes /nologo

OTA_VehLocDetailsNotifRQ.POS[0].RequestorID我希望在里面找到一处房产ID。然而,XSD.exe 工具生成的属性名为ID_Context.

你能解释它为什么这样做,以及我是否能够强制它生成正确的 ( ID) 属性名称?

请不要建议我编辑生成的文件,因为这不是可维护的方法。

接受答案后进一步编辑:

更仔细地查看 XSD 并将引用替换为其属性组定义,可以在其属性组中看到 ID 属性:

<xs:attributeGroup name="UniqueID_Group">
  <xs:attribute name="URL" type="xs:anyURI" />
  <xs:attribute name="Type" type="OTA_CodeType" use="required" />
  <xs:attribute name="Instance" type="StringLength1to32" />
  <xs:attributeGroup name="ID_Group">
    <xs:attribute name="ID" type="StringLength1to32" use="required" />
  </xs:attributeGroup>
  <xs:attribute name="ID_Context" type="StringLength1to32" use="optional" />
</xs:attributeGroup>

我相信这是 XSD 工具中的一个错误。

4

2 回答 2

2

让我们来看看....

  • RequestorID包含类型的复杂内容UniqueID_Type
  • UniqueID_Type包含对一组属性的引用,称为UniqueID_Group
  • UniqueID_Group是一个属性组,包含以下属性:
    • URL
    • Type
    • Instance
    • 一个参考ID_Group
    • ID_Context

我猜 C# 代码“ID_Context”是由于该属性组中的“ID_CONtext”属性而生成的……我看不出有什么问题。

但我确实同意 - 这ID_Group应该包括一个“ID”属性,但似乎 xsd.exe 已经放弃了对ID_Group- 无论出于何种原因的嵌套引用......这似乎是其他人在其他情况下偶然发现的问题,因为好。看起来 xsd.exe 无法处理此任务:-(

也许还可以看看这个讨论:

http://groups.google.com/group/OTA-Impl-Forum/browse_thread/thread/fa476cfb6e1fa7f7

更新:我也尝试了svcutil.exe来自 WCF(.NET 3.0 及更高版本) - 也没有运气:-(

Error: Type 'DateOrTimeOrDateTimeType' in namespace 'http://www.opentravel.org/OTA/2003/05' cannot be imported. Simple types with ** <union> content are not supported. Either change the schema so that the types can map to data contract types or use ImportXmlTyp e or use a different serializer.

于 2009-11-25T16:42:55.350 回答
2

A bit late, but I think I maybe found the solution to your problem (and right now my problem too):

http://www.opentravelcommunityforum.com/forum/viewtopic.php?f=8&t=19

I didn't tried yet, but I'm about to.

于 2010-04-22T02:59:06.523 回答