小编Ste*_*bka的帖子

在.NET中纠正"混合"类型的XML序列化和反序列化

我当前的任务涉及编写用于处理HL7 CDA文件的类库.
这些HL7 CDA文件是具有已定义XML模式的XML文件,因此我使用xsd.exe生成用于XML序列化和反序列化的.NET类.

XML Schema包含各种类型,其中包含mixed ="true"属性,指定此类型的XML节点可能包含与其他XML节点混合的普通文本.其中一种类型
的XML模式的相关部分如下所示:

<xs:complexType name="StrucDoc.Paragraph" mixed="true">
    <xs:sequence>
        <xs:element name="caption" type="StrucDoc.Caption" minOccurs="0"/>
        <xs:choice minOccurs="0" maxOccurs="unbounded">
            <xs:element name="br" type="StrucDoc.Br"/>
            <xs:element name="sub" type="StrucDoc.Sub"/>
            <xs:element name="sup" type="StrucDoc.Sup"/>
            <!-- ...other possible nodes... -->
        </xs:choice>
    </xs:sequence>
    <xs:attribute name="ID" type="xs:ID"/>
    <!-- ...other attributes... -->
</xs:complexType>
Run Code Online (Sandbox Code Playgroud)

将生成的代码这种类型如下:

/// <remarks/>
[System.CodeDom.Compiler.GeneratedCodeAttribute("xsd", "2.0.50727.3038")]
[System.SerializableAttribute()]
[System.Diagnostics.DebuggerStepThroughAttribute()]
[System.ComponentModel.DesignerCategoryAttribute("code")]
[System.Xml.Serialization.XmlTypeAttribute(TypeName="StrucDoc.Paragraph", Namespace="urn:hl7-org:v3")]
public partial class StrucDocParagraph {

    private StrucDocCaption captionField;

    private object[] itemsField;

    private string[] textField;

    private string idField;

    // ...fields for other …
Run Code Online (Sandbox Code Playgroud)

.net c# xml-serialization

18
推荐指数
1
解决办法
2万
查看次数

标签 统计

.net ×1

c# ×1

xml-serialization ×1