-3

我是 c# 的新手,我正在努力研究如何从我已经序列化到一个类中的一些 xml 中获取一个值。

我使用 xsd 构建了这个类,正如我在堆栈上找到的一个线程中所解释的那样。

任何人都可以帮我获得 LoginState 的价值吗?

这是我调试时看到的...

在此处输入图像描述

这是我将其序列化为的类:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace vCreate.Model
{
[System.CodeDom.Compiler.GeneratedCodeAttribute("xsd", "4.0.30319.17929")]
[System.SerializableAttribute()]
[System.Diagnostics.DebuggerStepThroughAttribute()]
[System.ComponentModel.DesignerCategoryAttribute("code")]
[System.Xml.Serialization.XmlTypeAttribute(AnonymousType = true)]
[System.Xml.Serialization.XmlRootAttribute(Namespace = "", IsNullable = false)]
public partial class NewDataSet
{

    private object[] itemsField;

    /// <remarks/>
    [System.Xml.Serialization.XmlElementAttribute("Table", typeof(NewDataSetTable), Form = System.Xml.Schema.XmlSchemaForm.Unqualified)]
    [System.Xml.Serialization.XmlElementAttribute("Table1", typeof(NewDataSetTable1), 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")]
[System.Xml.Serialization.XmlTypeAttribute(AnonymousType = true)]
public partial class NewDataSetTable
{

    private string loginStateField;

    private string loginMessageField;

    private string authIDField;

    private string userIDField;

    private string companyIDField;

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

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

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

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

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

/// <remarks/>
[System.CodeDom.Compiler.GeneratedCodeAttribute("xsd", "4.0.30319.17929")]
[System.SerializableAttribute()]
[System.Diagnostics.DebuggerStepThroughAttribute()]
[System.ComponentModel.DesignerCategoryAttribute("code")]
[System.Xml.Serialization.XmlTypeAttribute(AnonymousType = true)]
public partial class NewDataSetTable1
{

    private string languageIDField;

    private string languageDescriptionField;

    private string langLargeImageField;

    private string langThumbImageField;

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

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

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

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

}

4

2 回答 2

2

正如我们都理解的那样,您需要做的是resultingMessage.Items[0].LoginState获取登录状态并将其放入一个整数中。

int state = (resultingMessage.Items[0] as NewDataSetTable).LoginState;
于 2013-07-24T12:28:23.410 回答
1

现在您已经反序列化了 XML,您所要做的就是从 Dataset 中获取它。尝试关注

foreach (DataTable table in resultingMessage.Tables)
{
   foreach (DataRow row in table.Rows)
   {
     foreach (object item in row.ItemArray)
     {
        // read item
        var loginState = item.LoginState;
     }
   }
}
于 2013-07-24T12:29:37.280 回答