Generate class for schema with abstract complex ty

2019-06-24 02:48发布

问题:

I'm working with some schema which defines an abstract complex type, eg.

<xs:complexType name="MyComplexType" abstract="true">

This type is then referenced by another complex type in the schema:

<xs:complexType name="AnotherType">
  <xs:sequence>
    <xs:element name="Data" type="MyComplexType" maxOccurs="unbounded"/>
  </xs:sequence>
</xs:complexType>

When I run "xsd.exe /d /l:CS MySchema.xsd" I get this error:

Error: There was an error processing MySchema.xsd'. - Error generating code for DataSet ''. - Unable to convert input xml file content to a DataSet. DataSet cannot instantiate an abstract ComplexType for the node Data. - DataSet cannot instantiate an abstract ComplexType for the node Data.

It doesn't seem to be invalid schema. Has anyone else run into this issue?

Thanks

Nick

回答1:

After evaluating several different schema-to-code tools the only one we found that was able to deal with our schema (very large and extremely complicated) was Liquid XML (http://www.liquid-technologies.com/).



回答2:

I have never run into this problem, but I quickly learned that xsd.exe has a lot of shortcomings. We started using CodeXS a long time ago. The product is a web service, but the code is available as a command-line tool.

It has its own warts, but the code it generates is much better and it is free. Plus, it is extensible, and adding your own plug-ins for it is actually pretty easy.

Possibly, it won't have the same limitation?



回答3:

I know this is an old question, but I needed an answer for this question this week. I tried Liquid Studios as suggested by @ng5000 and found that software to be very clunky. Additionally, the cs output was so complicated that it gave me over 800 lines of code for a single entity with 12 simple properties.

I would highly recommend Xml2CSharp, a web tool that generates nice, simple POCOs with XML attribute decorators.