小编use*_*993的帖子

使用xsd.exe或xsd2code反序列化复杂的xsd模式(包含用于继承的substitutiongroup元素)

我在反序列化/序列化某些xsd模式时遇到问题,特别是在其中使用了替换组元素(substitutiongroup).我想要做的是从xsd架构生成C#类,然后处理对象,然后将它们序列化为有效的XML格式.有4个xsd文件,我用xsd2code或xsd.exe反序列化和序列化.这两种工具都会产生类似的不满意结果.它们忽略"substitutiongroup"元素,并且不会正确生成类成员.当我运行xsd.exe或xsd2code时,为BPMNPlane生成的c#类例如不包含成员BPMNShape(但BPMNDiagram类包含BPMNPlane).我试图更改生成的C#类(例如添加成员/属性),但生成的XML输出不正确.我想人们可以用linq-to-xml来掌握它,但它们是太多不同的元素,大约70,具有额外的属性属性.

<xsd:import namespace="http://www.omg.org/spec/DD/20100524/DC" schemaLocation="DC.xsd" />
<xsd:import namespace="http://www.omg.org/spec/DD/20100524/DI" schemaLocation="DI.xsd" />

<xsd:element name="BPMNDiagram" type="bpmndi:BPMNDiagram" />
<xsd:element name="BPMNPlane" type="bpmndi:BPMNPlane" />
<xsd:element name="BPMNLabelStyle" type="bpmndi:BPMNLabelStyle" />
<xsd:element name="BPMNShape" type="bpmndi:BPMNShape" substitutionGroup="di:DiagramElement" />
<xsd:element name="BPMNLabel" type="bpmndi:BPMNLabel" />
<xsd:element name="BPMNEdge" type="bpmndi:BPMNEdge" substitutionGroup="di:DiagramElement" />

<xsd:complexType name="BPMNDiagram">
    <xsd:complexContent>
        <xsd:extension base="di:Diagram">
            <xsd:sequence>
                <xsd:element ref="bpmndi:BPMNPlane" />
                <xsd:element ref="bpmndi:BPMNLabelStyle" maxOccurs="unbounded" minOccurs="0" />
            </xsd:sequence>
        </xsd:extension>
    </xsd:complexContent>
</xsd:complexType>


<xsd:complexType name="BPMNPlane">
    <xsd:complexContent>
        <xsd:extension base="di:Plane">    
    <xsd:attribute name="bpmnElement" type="xsd:QName" />       
        </xsd:extension>
    </xsd:complexContent>
</xsd:complexType>

<xsd:complexType name="BPMNEdge">
    <xsd:complexContent>
        <xsd:extension base="di:LabeledEdge">
            <xsd:sequence>
                <xsd:element ref="bpmndi:BPMNLabel" minOccurs="0" />
            </xsd:sequence>
            <xsd:attribute name="bpmnElement" type="xsd:QName" /> …
Run Code Online (Sandbox Code Playgroud)

serialization xsd linq-to-xml xsd2code deserialization

4
推荐指数
1
解决办法
3429
查看次数