C# 尝试使用c反序列化xml负载时出现的问题#

C# 尝试使用c反序列化xml负载时出现的问题#,c#,xml,C#,Xml,我正在尝试反序列化来自api的xml。 我已经使用xsd.exe将xsd的in转换为c#类。 我使用的类如下所示: /// <remarks/> [System.CodeDom.Compiler.GeneratedCodeAttribute("xsd", "2.0.50727.3038")] [System.SerializableAttribute()] [System.Diagnostics.DebuggerStepThroughAttribute()] [System.Comp

我正在尝试反序列化来自api的xml。 我已经使用xsd.exe将xsd的in转换为c#类。 我使用的类如下所示:

/// <remarks/>
[System.CodeDom.Compiler.GeneratedCodeAttribute("xsd", "2.0.50727.3038")]
[System.SerializableAttribute()]
[System.Diagnostics.DebuggerStepThroughAttribute()]
[System.ComponentModel.DesignerCategoryAttribute("code")]
[System.Xml.Serialization.XmlTypeAttribute(AnonymousType=true)]
[System.Xml.Serialization.XmlRootAttribute("OfficerSearch", Namespace="http://xmlgw.companieshouse.gov.uk/v1-0/schema", IsNullable=false)]
public partial class OfficerSearch {

    private string continuationKeyField;

    private string searchRowsField;

    private OfficerSearchItem[] officerSearchItemField;

    /// <remarks/>
    public string ContinuationKey {
        get {
            return this.continuationKeyField;
        }
        set {
            this.continuationKeyField = value;
        }
    }

    /// <remarks/>
    [System.Xml.Serialization.XmlElementAttribute(DataType="integer")]
    public string SearchRows {
        get {
            return this.searchRowsField;
        }
        set {
            this.searchRowsField = value;
        }
    }

    /// <remarks/>
    [System.Xml.Serialization.XmlElementAttribute("OfficerSearchItem")]
    public OfficerSearchItem[] OfficerSearchItem {
        get {
            return this.officerSearchItemField;
        }
        set {
            this.officerSearchItemField = value;
        }
    }
}
/// <remarks/>
[System.CodeDom.Compiler.GeneratedCodeAttribute("xsd", "2.0.50727.3038")]
[System.SerializableAttribute()]
[System.Diagnostics.DebuggerStepThroughAttribute()]
[System.ComponentModel.DesignerCategoryAttribute("code")]
[System.Xml.Serialization.XmlTypeAttribute(AnonymousType=true)]
[System.Xml.Serialization.XmlRootAttribute("OfficerSearchItem", Namespace="", IsNullable=false)]
public partial class OfficerSearchItem : OfficerSearchItemBase {

    private string personIDField;

    private SearchMatch searchMatchField;

    private bool searchMatchFieldSpecified;

    private OfficerSearchItemBase[] duplicateOfficersField;

    /// <remarks/>
    public string PersonID {
        get {
            return this.personIDField;
        }
        set {
            this.personIDField = value;
        }
    }

    /// <remarks/>
    public SearchMatch SearchMatch {
        get {
            return this.searchMatchField;
        }
        set {
            this.searchMatchField = value;
        }
    }

    /// <remarks/>
    [System.Xml.Serialization.XmlIgnoreAttribute()]
    public bool SearchMatchSpecified {
        get {
            return this.searchMatchFieldSpecified;
        }
        set {
            this.searchMatchFieldSpecified = value;
        }
    }

    /// <remarks/>
    [System.Xml.Serialization.XmlArrayItemAttribute("DuplicateOfficerSearchItem", IsNullable=false)]
    public OfficerSearchItemBase[] DuplicateOfficers {
        get {
            return this.duplicateOfficersField;
        }
        set {
            this.duplicateOfficersField = value;
        }
    }
}

/// <remarks/>
[System.CodeDom.Compiler.GeneratedCodeAttribute("xsd", "2.0.50727.3038")]
[System.SerializableAttribute()]
[System.Diagnostics.DebuggerStepThroughAttribute()]
[System.ComponentModel.DesignerCategoryAttribute("code")]
[System.Xml.Serialization.XmlRootAttribute("DuplicateOfficerSearchItem", Namespace="", IsNullable=false)]
public partial class OfficerSearchItemBase {

    private string titleField;

    private string surnameField;

    private string forenameField;

    private System.DateTime dOBField;

    private string postTownField;

    private string postcodeField;

    private string countryOfResidenceField;

    /// <remarks/>
    public string Title {
        get {
            return this.titleField;
        }
        set {
            this.titleField = value;
        }
    }

    /// <remarks/>
    public string Surname {
        get {
            return this.surnameField;
        }
        set {
            this.surnameField = value;
        }
    }

    /// <remarks/>
    public string Forename {
        get {
            return this.forenameField;
        }
        set {
            this.forenameField = value;
        }
    }

    /// <remarks/>
    [System.Xml.Serialization.XmlElementAttribute(DataType="date")]
    public System.DateTime DOB {
        get {
            return this.dOBField;
        }
        set {
            this.dOBField = value;
        }
    }

    /// <remarks/>
    public string PostTown {
        get {
            return this.postTownField;
        }
        set {
            this.postTownField = value;
        }
    }

    /// <remarks/>
    public string Postcode {
        get {
            return this.postcodeField;
        }
        set {
            this.postcodeField = value;
        }
    }

    /// <remarks/>
    public string CountryOfResidence {
        get {
            return this.countryOfResidenceField;
        }
        set {
            this.countryOfResidenceField = value;
        }
    }
}
//
[System.CodeDom.Compiler.GeneratedCodeAttribute(“xsd”、“2.0.50727.3038”)]
[System.SerializableAttribute()]
[System.Diagnostics.DebuggerStepThroughAttribute()]
[System.ComponentModel.DesignerCategoryAttribute(“代码”)]
[System.Xml.Serialization.XmlTypeAttribute(AnonymousType=true)]
[System.Xml.Serialization.XmlRootAttribute(“OfficerSearch”,命名空间=”http://xmlgw.companieshouse.gov.uk/v1-0/schema“,IsNullable=false)]
公共部分类公务员搜索{
私有字符串continuationKeyField;
私有字符串搜索rowsfield;
private OfficerSearchItem[]OfficerSearchItem字段;
/// 
公共字符串连续键{
得到{
返回此.continuationKeyField;
}
设置{
this.continuationKeyField=值;
}
}
/// 
[System.Xml.Serialization.xmlementAttribute(DataType=“integer”)]
公共字符串搜索行{
得到{
返回此.searchRowsField;
}
设置{
this.searchRowsField=值;
}
}
/// 
[System.Xml.Serialization.XmlElementAttribute(“OfficerSearchItem”)]
公职人员搜索项目[]公职人员搜索项目{
得到{
返回此.officerSearchItemField;
}
设置{
this.officerSearchItemField=值;
}
}
}
/// 
[System.CodeDom.Compiler.GeneratedCodeAttribute(“xsd”、“2.0.50727.3038”)]
[System.SerializableAttribute()]
[System.Diagnostics.DebuggerStepThroughAttribute()]
[System.ComponentModel.DesignerCategoryAttribute(“代码”)]
[System.Xml.Serialization.XmlTypeAttribute(AnonymousType=true)]
[System.Xml.Serialization.XmlRootAttribute(“OfficerSearchItem”,Namespace=“”,IsNullable=false)]
公共部分类OfficerSearchItem:OfficerSearchItemBase{
私有字符串personIDField;
私有搜索匹配搜索匹配字段;
指定的专用布尔搜索匹配字段;
private OfficerSearchItemBase[]Duplicate OfficersField;
/// 
公共字符串拟人{
得到{
返回此.personIDField;
}
设置{
this.personIDField=值;
}
}
/// 
公共搜索匹配搜索匹配{
得到{
返回此.searchMatchField;
}
设置{
this.searchMatchField=值;
}
}
/// 
[System.Xml.Serialization.XmlIgnoreAttribute()]
指定公共布尔搜索匹配{
得到{
返回指定的此.SearchMatchField;
}
设置{
this.searchMatchFieldSpecified=值;
}
}
/// 
[System.Xml.Serialization.XmlArrayItemAttribute(“DuplicateOfficerSearchItem”,IsNullable=false)]
公职人员搜索项目库[]名公职人员{
得到{
返回此.duplicateOfficersField;
}
设置{
this.duplicateOfficersField=值;
}
}
}
/// 
[System.CodeDom.Compiler.GeneratedCodeAttribute(“xsd”、“2.0.50727.3038”)]
[System.SerializableAttribute()]
[System.Diagnostics.DebuggerStepThroughAttribute()]
[System.ComponentModel.DesignerCategoryAttribute(“代码”)]
[System.Xml.Serialization.XmlRootAttribute(“DuplicateOfficerSearchItem”,Namespace=”“,IsNullable=false)]
公共部分类OfficerSearchItemBase{
私有字符串标题字段;
私有字符串字段;
私有字符串名称字段;
private System.DateTime字段;
私有字符串postTownField;
私有字符串邮政编码字段;
私有字符串地址字段;
/// 
公共字符串标题{
得到{
把这个还给我;
}
设置{
this.titleField=值;
}
}
/// 
公共字符串姓氏{
得到{
返回此字段;
}
设置{
this.name字段=值;
}
}
/// 
公共字符串名{
得到{
返回此.forenameField;
}
设置{
this.forenameField=值;
}
}
/// 
[System.Xml.Serialization.xmlementAttribute(DataType=“date”)]
公共系统.日期时间DOB{
得到{
把这个还给多伯菲尔德;
}
设置{
this.dobbield=值;
}
}
/// 
公共邮政城{
得到{
返回此.postTownField;
}
设置{
this.postTownField=值;
}
}
/// 
公共字符串邮政编码{
得到{
返回此.postcodeField;
}
设置{
this.postcodeField=值;
}
}
/// 
公共字符串常驻国{
得到{
返回此.countryOfResidenceField;
}
设置{
this.countryOfResidenceField=值;
}
}
}
除OfficerSearchItems数组外,所有内容都反序列化。 这些类对应的xml模式为:

<?xml version="1.0" encoding="UTF-8"?>
<!-- Companies House XML Gateway Schema -->
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" elementFormDefault="qualified" attributeFormDefault="unqualified">
    <xs:include schemaLocation="chbase-v2-3.xsd"/>
    <xs:element name="OfficerSearchRequest">
        <xs:annotation>
            <xs:documentation>Officer Search Request</xs:documentation>
        </xs:annotation>
        <xs:complexType>
            <xs:sequence>
                <xs:element ref="Surname"/>
                <xs:element ref="Forename" minOccurs="0" maxOccurs="2"/>
                <xs:element ref="PostTown" minOccurs="0"/>
                <xs:element ref="OfficerType"/>
                <xs:element name="CountryOfResidence" type="xs:string" minOccurs="0">
                    <xs:annotation>
                        <xs:documentation>Normal country of residence for the officer</xs:documentation>
                    </xs:annotation>
                </xs:element>
                <xs:element ref="IncludeResignedInd" minOccurs="0"/>
                <xs:element ref="ContinuationKey" minOccurs="0"/>
            </xs:sequence>
        </xs:complexType>
    </xs:element>
    <xs:element name="OfficerSearch">
        <xs:annotation>
            <xs:documentation>Officer Search Result</xs:documentation>
        </xs:annotation>
        <xs:complexType>
            <xs:sequence>
                <xs:element ref="ContinuationKey" minOccurs="0"/>
                <xs:element ref="SearchRows"/>
                <xs:element ref="OfficerSearchItem" minOccurs="0" maxOccurs="unbounded"/>
            </xs:sequence>
        </xs:complexType>
    </xs:element>
</xs:schema>

警官搜查请求
该官员的正常居住国
警官搜索结果
一些示例输出是:

    <OfficerSearch xmlns="http://xmlgw.companieshouse.gov.uk/v1-0/schema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://xmlgw.companieshouse.gov.uk/v1-0/schema http://xmlgw.companieshouse.gov.uk/v1-0/schema/OfficerSearch-v2-3.xsd">
  <ContinuationKey>f80bf6eJyl0ttr1EAUB+C1bbrb6YqXqvF+rdqigSRLV8zbjoKttiqtYH0aJpmTJuhmYibB7qP+5f5mrLIUHwQDH8wl58yZk3j9Ne5xNhSZzApS7+URGT74ztlAyLpuZzVx1rP7RXlUkGntC25/VdQYvu2mKTVugdkA08q2+5VgWaWfaWb4Qq/XO8OG4dxj81V07JK9oRn3sRtjfRSGURwjVGQVEtvCBu4Y+xI7fKGntaxKMtu6M5Qk7/K8zKg5INlkRZLo+em2rNQXTKZlW4jJ/v7k00Z4nMaxTNNsU0TB38rZ1VK5k04Va8uRU7Ll9EVuhzH3l17rouLME11XKs7Wt7I0zEcUBXGksoDGRME4zWWg4mdjGW1R/FyNOFsRtTZtq79Vc9ki7vcnVVvoamYvbLrGHcc8V71dUqX5ulOpk8Ybd8MP9tt4NmWuG3IRttULf3L9LnEoTjrjIvzFlzsHP5LTvTzc23318Z9a+h+hm/ZXsDXCIiyBB8vQhwGsAINVGMJZOAfn4QJchDW4BJfhCvhwFa7BdbgBN+EW3IY7cBfuwX14AOvwEB7BY9iAJ/D0J6I2wvE=</ContinuationKey>
  <SearchRows>35</SearchRows>
  <OfficerSearchItem>
    <Title></Title>
    <Surname>SLATER</Surname>
    <Forename>DAVID STUART</Forename>
    <DOB>1966-09-15</DOB>
    <PostTown>MUCH WENLOCK</PostTown>
    <Postcode>TF13 </Postcode>
    <PersonID>CSeJxNkNFqgzAUhu/3FOK91aTVbZCmCG7gGAxa21uJ5lhDa3RJHPPt1+isvQn/+b6fcBKy+22uzg8oLVq5ddEqcB2QZcuFPG/dY/buvbjOjj6RCwy3k3WdNsz0miLiL4PlZuiAjnBKXKhKsgYQjaWpWzkQf0F3i+lHW8tF4Um1CuxEk/iUJs4hO8b7bCrNxtZ0r8Z8+Iyzt/3oZ2S1EeZqV1oiF/o7ldwuP0dyySEfcpFz+lVVogSVJsRfIOnYGezjw7IIqjUgDyNeehABeFFRMY/j54ihEPArXxN/bpMOlOybguIgCDYojBC+yX9GNDBV1tn0Y4+Dvlf8h2gv/AOdGJNe</PersonID>
    </OfficerSearchItem>
  <OfficerSearchItem>
    <Title></Title>
    <Surname>SLATER</Surname>
    <Forename>PETER THOMAS ANTHONY</Forename>
    <DOB>1960-01-29</DOB>
    <PostTown>PRESTON</PostTown>
    <Postcode>PR2 </Postcode>
    <PersonID>CSeJxNkF1PgzAUhu/9FYR7hMKGLum6kDjjjG7G4YVXpNDT0WwUbIuRfy+FMHbTPO9HetqDN3/VxfkFpUUt1y66D1wHZFEzIU9r9yt99h5dZ0Pu8Bm6/qRNow01rSYI+7OwvukaIIM5EhOKS1oBIok0ZS077M/WNQ3Ja13KOQrHqFZgFfnYpttPJ305vCdHJ9n3sP8ey1PD1nWrBj6+JX19yCfLxkaYi33ajEzon51k9hMT4nMGWZeJjJED56IAtXvC/mzihp7ALmFZ5AGPAHkhYoUHMYAX55x6LHyIKVpCuGIR9qc2bkDJtspJEKAVCqLFop85eVgDVUWZjpu7Ffpa8W/QXvgPvUeVog==</PersonID>
    </OfficerSearchItem>
</OfficerSearch>

4.6 6六六六六六六六六六六六六六六六六六六六六六六六六六六六六六六六六六六六六六六六六六六六六六六六六六六六六六六六六六六六六六六六六六六六六六六六六六六六六六六六六六六六六六六六六六六六六六六六六六六六六六六六六六六六六六六六六六六六六六六六六六六六六六六六六六六六六六六六六六六六六六六六六六六六六六六六六六六六六六六六六六六六六六六六六六六六六六六六六六六六六六六六六六六六六六六六六六六六六六六六六六六六六六六六六六六六六六六六六六六六六六六六六六六六六六六六六六六六六六5k0