关于XML反序列化

时间:2013-06-05 04:30:56

标签: c# xml deserialization xml-deserialization

这是关于XML反序列化的一个非常简单的问题。

我这里有一个简单的XML(部分,为了使这个问题变小)

<iqu>
    </items>
        <item>
            <installedsize></installedsize>
            <softwareid>58907ba6-538b-424a-bfe4-98391857b1b1</softwareid>
            <active>1</active>
            <installdate>2013-06-03T21:02:07</installdate>
            <installdisplaydate>Jun 3, 2013 9:02 PM</installdisplaydate>
            <currentstate>0</currentstate>
            <isinstalled>true</isinstalled>
            <uninstallkeys>
                <key type="software">
                    <![CDATA[Pidgin]]>
                </key>
            </uninstallkeys>
        </item>
    </items>
</iqu>

我已经为反序列化做了一个类对象

using GalaSoft.MvvmLight;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace UninstallHelper.Model
{
    public class Model_W3i_InstallationData : ViewModelBase
    {
        public class Item : ViewModelBase
        {
            private string _installedsize = string.Empty;
            public string installedsize
            {
                get { return _installedsize; }
                set
                {
                    if (_installedsize != value)
                    {
                        _installedsize = value;
                        base.RaisePropertyChanged("installedsize");
                    }
                }
            }

            private string _softwareid = string.Empty;
            public string softwareid
            {
                get { return _softwareid; }
                set
                {
                    if (_softwareid != value)
                    {
                        _softwareid = value;
                        base.RaisePropertyChanged("softwareid");
                    }
                }
            }

            private string _active = string.Empty;
            public string active
            {
                get { return _active; }
                set
                {
                    if (_active != value)
                    {
                        _active = value;
                        base.RaisePropertyChanged("active");
                    }
                }
            }

            private string _displayname = string.Empty;
            public string displayname
            {
                get { return _displayname; }
                set
                {
                    if (_displayname != value)
                    {
                        _displayname = value;
                        base.RaisePropertyChanged("displayname");
                    }
                }
            }

            private string _runcommand = string.Empty;
            public string runcommand
            {
                get { return _runcommand; }
                set
                {
                    if (_runcommand != value)
                    {
                        _runcommand = value;
                        base.RaisePropertyChanged("runcommand");
                    }
                }
            }

            private string _installdate = string.Empty;
            public string installdate
            {
                get { return _installdate; }
                set
                {
                    if (_installdate != value)
                    {
                        _installdate = value;
                        base.RaisePropertyChanged("installdate");
                    }
                }
            }

            private string _installdisplaydate = string.Empty;
            public string installdisplaydate
            {
                get { return _installdisplaydate; }
                set
                {
                    if (_installdisplaydate != value)
                    {
                        _installdisplaydate = value;
                        base.RaisePropertyChanged("installdisplaydate");
                    }
                }
            }

            private string _versionid = string.Empty;
            public string versionid
            {
                get { return _versionid; }
                set
                {
                    if (_versionid != value)
                    {
                        _versionid = value;
                        base.RaisePropertyChanged("versionid");
                    }
                }
            }

            private string _ignoreversion = string.Empty;
            public string ignoreversion
            {
                get { return _ignoreversion; }
                set
                {
                    if (_ignoreversion != value)
                    {
                        _ignoreversion = value;
                        base.RaisePropertyChanged("ignoreversion");
                    }
                }
            }

            private string _campaignid = string.Empty;
            public string campaignid
            {
                get { return _campaignid; }
                set
                {
                    if (_campaignid != value)
                    {
                        _campaignid = value;
                        base.RaisePropertyChanged("campaignid");
                    }
                }
            }

            private string _productsessionid = string.Empty;
            public string productsessionid
            {
                get { return _productsessionid; }
                set
                {
                    if (_productsessionid != value)
                    {
                        _productsessionid = value;
                        base.RaisePropertyChanged("productsessionid");
                    }
                }
            }

            private string _installtype = string.Empty;
            public string installtype
            {
                get { return _installtype; }
                set
                {
                    if (_installtype != value)
                    {
                        _installtype = value;
                        base.RaisePropertyChanged("installtype");
                    }
                }
            }

            private string _updateurl = string.Empty;
            public string updateurl
            {
                get { return _updateurl; }
                set
                {
                    if (_updateurl != value)
                    {
                        _updateurl = value;
                        base.RaisePropertyChanged("updateurl");
                    }
                }
            }

            private string _offerid = string.Empty;
            public string offerid
            {
                get { return _offerid; }
                set
                {
                    if (_offerid != value)
                    {
                        _offerid = value;
                        base.RaisePropertyChanged("offerid");
                    }
                }
            }

            private string _classid = string.Empty;
            public string classid
            {
                get { return _classid; }
                set
                {
                    if (_classid != value)
                    {
                        _classid = value;
                        base.RaisePropertyChanged("classid");
                    }
                }
            }

            private string _currentstate = string.Empty;
            public string currentstate
            {
                get { return _currentstate; }
                set
                {
                    if (_currentstate != value)
                    {
                        _currentstate = value;
                        base.RaisePropertyChanged("currentstate");
                    }
                }
            }

            private string _isinstalled = string.Empty;
            public string isinstalled
            {
                get { return _isinstalled; }
                set
                {
                    if (_isinstalled != value)
                    {
                        _isinstalled = value;
                        base.RaisePropertyChanged("isinstalled");
                    }
                }
            }

            private string _uninstallinfo = string.Empty;
            public string uninstallinfo
            {
                get { return _uninstallinfo; }
                set
                {
                    if (_uninstallinfo != value)
                    {
                        _uninstallinfo = value;
                        base.RaisePropertyChanged("uninstallinfo");
                    }
                }
            }
        }
    }
}

这里的问题是关于我向你展示的XML中的这个节点(上图)

<uninstallkeys>
    <key type="software">
        <![CDATA[Pidgin]]>
    </key>
</uninstallkeys>

反序列化这部分的正确方法是什么?

0 个答案:

没有答案