Trouble with XML Deserialization into XSD generated classes

后端 未结 4 1708
无人共我
无人共我 2021-01-02 02:11

I have a rather detailed xml file. Below is the top level nodes (I have included the ellipse as the lower level nodes are all well formed and properly filled with data):

相关标签:
4条回答
  • 2021-01-02 02:49

    XSD.EXE is a good start - but it's far from perfect. Also, based on the XML you provided, XSD.EXE can't always decide for sure whether something is a single instance of an object, or an open-ended array of objects.

    This seems to be the case for your two elements - Application.Lease and Application.CashFlow. How are they defined in the generated XSD file? Does that make sense to you? Quite possibly, you'd have to add a little hints, such as:

    <xs:element name="Lease" minOccurs="0" maxOccurs="1" />
    

    for an optional property, that's zero or one occurences only. Things like that are really hard for the xsd.exe tool to figure out based on just a single XML sample file.

    Marc

    0 讨论(0)
  • 2021-01-02 02:50

    Another issue that can cause this problem is that the xml file contents between the tags (meaning the content) is still encoded when it shouldn't be. For example, the <br> tags in my content were still <br> instead of &lt;br /&gt;. The xsd generator turned these into elements in the schema then mislabeled them as unbounded since there was more than one found. Unencoding them fixed the problem and generated the classes correctly.

    0 讨论(0)
  • 2021-01-02 02:53

    Go to your generated class and change all from [][] ---> []

    0 讨论(0)
  • 2021-01-02 02:56

    There's an issue with xsd.exe and lists. You have to go into the generated class and manually edit the file to the correct type. I've switched to using Xsd2Code. So far it doesn't seem to have this problem.

    0 讨论(0)
提交回复
热议问题