反序列化XML不会填充内部对象

时间:2014-05-08 14:49:19

标签: c# xml serialization xsd

我试图基于xsd为这个xsd.exe反序列化一个xml来生成下面的类结构是生成的类的一部分

public partial class tsResponse {

    private object[] itemsField;

    /// <remarks/>
    [System.Xml.Serialization.XmlElementAttribute("credentials", typeof(credentialsType), Form=System.Xml.Schema.XmlSchemaForm.Unqualified)]
        public object[] Items {
        get {
            return this.itemsField;
        }
        set {
            this.itemsField = value;
        }
    }
}


    /// <remarks/>
[System.CodeDom.Compiler.GeneratedCodeAttribute("xsd", "4.0.30319.17929")]
[System.SerializableAttribute()]
[System.Diagnostics.DebuggerStepThroughAttribute()]
[System.ComponentModel.DesignerCategoryAttribute("code")]

public partial class credentialsType {

    private credentialsTypeSite siteField;

    private object userField;

    private string nameField;

    private string passwordField;

    private string tokenField;

    /// <remarks/>
    [System.Xml.Serialization.XmlElementAttribute(Form=System.Xml.Schema.XmlSchemaForm.Unqualified)]
    public credentialsTypeSite site {
        get {
            return this.siteField;
        }
        set {
            this.siteField = value;
        }
    }

    /// <remarks/>
    [System.Xml.Serialization.XmlElementAttribute(Form=System.Xml.Schema.XmlSchemaForm.Unqualified)]
    public object user {
        get {
            return this.userField;
        }
        set {
            this.userField = value;
        }
    }

    /// <remarks/>
    [System.Xml.Serialization.XmlAttributeAttribute()]
    public string name {
        get {
            return this.nameField;
        }
        set {
            this.nameField = value;
        }
    }

    /// <remarks/>
    [System.Xml.Serialization.XmlAttributeAttribute()]
    public string password {
        get {
            return this.passwordField;
        }
        set {
            this.passwordField = value;
        }
    }

    /// <remarks/>
    [System.Xml.Serialization.XmlAttributeAttribute()]
    public string token {
        get {
            return this.tokenField;
        }
        set {
            this.tokenField = value;
        }
    }
}

但是现在当我尝试反序列化下面的XML时,没有在items数组中填充凭据类型

   <?xml version="1.0" encoding="UTF-8"?>
    <tsResponse xmlns="http://tableausoftware.com/api" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://tableausoftware.com/api http://tableausoftware.com/api/ts-api-2.0.xsd">
      <credentials token="79ec436cc643dda259184206b966d5bf">
        <site contentUrl=""/>
      </credentials>
     </tsResponse>

我不明白为什么会这样,请帮助。

0 个答案:

没有答案