tags:

views:

220

answers:

2

I'm generating C# classes from an OTA (Open Travel Alliance) XSD file. You can download the XSD file from here.

I create the C# class with the following command in a Visual Studio Command Prompt:

xsd FS_OTA_VehLocDetailsNotifRQ.xsd /classes /nologo

Within OTA_VehLocDetailsNotifRQ.POS[0].RequestorID I would expect to find an ID property. Yet the property generated by the XSD.exe tool is named ID_Context.

Can you explain why it does this, and whether I am able to force it to generate the correct (ID) property name?

Please don't suggest I edit the generated file as that is not a maintainable approach.

Further edit after accepting the answer:

Looking at the XSD more closely and replacing the references with their attribute group definitions, the ID attribute can be seen in its attribute group:

<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>

I believe this to be a bug in the XSD tool.

+1  A: 

Let's see....

  • the RequestorID contains complex content of type UniqueID_Type
  • UniqueID_Type contains a reference to a group of attributes called UniqueID_Group
  • UniqueID_Group is an attribute group and contains the following attributes:
    • URL
    • Type
    • Instance
    • a reference to an ID_Group
    • ID_Context

I guess the C# code "ID_Context" is generated because of the "ID_COntext" attribute in that attribute group... I don't see anything wrong with that.

But I do agree - that ID_Group should include an "ID" property, but it seems xsd.exe has dropped that nested reference to the ID_Group - for whatever reason... it does appear to be a problem others have stumbled across in other scenarios, as well. Looks like xsd.exe cannot handle this task :-(

Maybe also check out this discussion:

http://groups.google.com/group/OTA-Impl-Forum/browse%5Fthread/thread/fa476cfb6e1fa7f7

Update: I also tried the svcutil.exe from WCF (.NET 3.0 and up) - no luck either :-(

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.

marc_s
Wow, I missed that step; well done. As you say, the skipping of the `ID_Group` is the problem. What a pity it's attribute.
Bernhard Hofmann
A: 

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&amp;t=19

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

Luiggi
I don't think that solves this particular issue, but if it does please share the fix here. THANKS!
Bernhard Hofmann
Yes, it worked for me. I had the same issue and by nesting I could fix it!
Luiggi