0

I am trying to use xsd or xsd2code to generate a c# class from an XSD file. The XSD file is from a third party, and cannot be modified.

It does generate classes, but they include blocks like this.

[XmlElement("ABOUT_VERSIONS", typeof(ABOUT_VERSIONS), Order=0)]
[XmlElement("ASSETS", typeof(ASSETS), Order=0)]
[XmlElement("COLLATERALS", typeof(COLLATERALS), Order=0)]
[XmlElement("COMMUNICATION_EVENTS", typeof(COMMUNICATION_EVENTS), Order=0)]
[XmlElement("DEAL_DETAIL", typeof(DEAL_DETAIL), Order=0)]
[XmlElement("EXPENSES", typeof(EXPENSES), Order=0)]
[XmlElement("EXTENSION", typeof(DEAL_EXTENSION), Order=0)]
[XmlElement("LIABILITIES", typeof(LIABILITIES), Order=0)]
[XmlElement("LITIGATIONS", typeof(LITIGATIONS), Order=0)]
[XmlElement("LOANS", typeof(LOANS), Order=0)]
[XmlElement("PARTIES", typeof(PARTIES), Order=0)]
[XmlElement("REFERENCE", typeof(REFERENCE), Order=0)]
[XmlElement("RELATIONSHIPS", typeof(RELATIONSHIPS), Order=0)]
[XmlElement("SERVICES", typeof(SERVICES), Order=0)]
[XmlElement("SUPPORTING_RECORD_SETS", typeof(SUPPORTING_RECORD_SETS), Order=0)]
public List<object> Items { get; set; }

In simpler classes in the past I have just manually edited the output to make the classes useful, replacing it with something like this

[XmlElement("ABOUT_VERSIONS", typeof(ABOUT_VERSIONS), Order=0)])]
public List<ABOUT_VERSIONS> ABOUT_VERSIONS { get; set; }
[XmlElement("ASSETS", typeof(ASSETS), Order=0)])]
public List<ASSETS> ASSETS { get; set; }
...

This output is incredibly large (nearly 9MB of output class file), and the output is full of similar blocks. It would take days to go through and manually edit the auto generated classes, only to have to do it again the next time they release an update (This is the MISMO message standard if you are curious. It is an xml data transfer standard written by a bunch of non-technical banking executives. It is probably worse than you are thinking.).

So is there a way to force xsd or xsd2code, or some other tool, to auto-generate c# classes that separate each of the possible child classes into their own list rather than clumping them together into an object list?

athelred
  • 21
  • 2
  • No. You have have a base class with a lot of inherited classes and your list can be one or more of the inherited classes. The xml structure and the class structure has to map one-to-one. changing the class structure xml serialization will not work and you would have to develop a custom serializer. – jdweng Aug 17 '20 at 14:33
  • @jdweng: That comment is a useful response, but it would be even more useful if you added it as an answer. You would have more space to explain, better formatting options, and it would be easier for others to respond to your points. – kimbert Aug 18 '20 at 13:32

0 Answers0