Xsd2Code 省略某些字段
我正在使用 Xsd2Code 从 XML 模式生成类。它适用于某些复杂类型,如下所示:
<xs:complexType name="AsiguratB1Type">
<xs:sequence>
<xs:element name="asiguratB11" type="AsiguratB11Type" minOccurs="0" maxOccurs="10"/>
</xs:sequence>
<xs:attribute name="B1_1" type="typ:TipAsiguratSType" use="required"/>
<xs:attribute name="B1_2" type="typ:FlagSType" use="required"/>
<xs:attribute name="B1_3" type="typ:TipContractSType" use="required"/>
<xs:attribute name="B1_4" type="typ:OreNormaZiSType" use="required"/>
<xs:attribute name="B1_5" type="typ:Pozitiv15SType"/>
<xs:attribute name="B1_6" type="typ:Pozitiv3SType"/>
<xs:attribute name="B1_7" type="typ:Pozitiv3SType"/>
<xs:attribute name="B1_8" type="typ:Pozitiv3SType"/>
<xs:attribute name="B1_9" type="typ:Pozitiv2SType"/>
<xs:attribute name="B1_10" type="typ:Pozitiv15SType"/>
<xs:attribute name="B1_15" type="typ:Pozitiv2SType"/>
</xs:complexType>
...而对于其他类型(下面的示例),它仅生成空白类(仅序列化例程,没有字段)。
<xs:complexType name="AngajatorAType">
<xs:complexContent>
<xs:restriction base="xs:anyType">
<xs:attribute name="A_codOblig" type="typ:CodObligSType" use="required"/>
<xs:attribute name="A_codBugetar" type="typ:CodBugetarSType" use="required"/>
<xs:attribute name="A_datorat" type="typ:Pozitiv15SType" use="required"/>
<xs:attribute name="A_deductibil" type="typ:Pozitiv15SType"/>
<xs:attribute name="A_plata" type="typ:Pozitiv15SType" use="required"/>
</xs:restriction>
</xs:complexContent>
</xs:complexType>
VS2010 工具集中的 xsd.exe 也会发生同样的情况。 您认为可能是什么问题?
I'm using Xsd2Code to generate classes from an XML schema. It works for some complex types like the following:
<xs:complexType name="AsiguratB1Type">
<xs:sequence>
<xs:element name="asiguratB11" type="AsiguratB11Type" minOccurs="0" maxOccurs="10"/>
</xs:sequence>
<xs:attribute name="B1_1" type="typ:TipAsiguratSType" use="required"/>
<xs:attribute name="B1_2" type="typ:FlagSType" use="required"/>
<xs:attribute name="B1_3" type="typ:TipContractSType" use="required"/>
<xs:attribute name="B1_4" type="typ:OreNormaZiSType" use="required"/>
<xs:attribute name="B1_5" type="typ:Pozitiv15SType"/>
<xs:attribute name="B1_6" type="typ:Pozitiv3SType"/>
<xs:attribute name="B1_7" type="typ:Pozitiv3SType"/>
<xs:attribute name="B1_8" type="typ:Pozitiv3SType"/>
<xs:attribute name="B1_9" type="typ:Pozitiv2SType"/>
<xs:attribute name="B1_10" type="typ:Pozitiv15SType"/>
<xs:attribute name="B1_15" type="typ:Pozitiv2SType"/>
</xs:complexType>
... while for others (example below) it just generates blank classes (only serialization routines, no fields).
<xs:complexType name="AngajatorAType">
<xs:complexContent>
<xs:restriction base="xs:anyType">
<xs:attribute name="A_codOblig" type="typ:CodObligSType" use="required"/>
<xs:attribute name="A_codBugetar" type="typ:CodBugetarSType" use="required"/>
<xs:attribute name="A_datorat" type="typ:Pozitiv15SType" use="required"/>
<xs:attribute name="A_deductibil" type="typ:Pozitiv15SType"/>
<xs:attribute name="A_plata" type="typ:Pozitiv15SType" use="required"/>
</xs:restriction>
</xs:complexContent>
</xs:complexType>
The same thing happens with xsd.exe from the VS2010 toolset.
What do you think could be the problem?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我想说这是设计使然。限制不能向基本类型添加新的属性或元素或任何内容。
I'd say it is by design. A restriction can't add NEW attributes or elements or anything to the base type.
我认为当您针对 4.0 框架时,xsd2code 如何处理 minOccus=0 可能存在问题。您能暂时删除它并查看序列化的内容吗?
似乎也有效的方法是针对 3.5 框架并包含 xml 属性。
I think there might be an issue how xsd2code is handling the minOccus=0 when you target 4.0 framework. Would you be able to temporarily remove that and see what is serialized?
What also seems to work is to target the 3.5 framework and include the xml attributes.