如何为以下xml创建模型类。
<?xml version="1.0"?>
<NOTIFICATION>
<NOTIF_HEADER>
<SOURCE>FCDB</SOURCE>
<MSGID>585995798502256</MSGID>
<TXN_ID>UTP</TXN_ID>
</NOTIF_HEADER>
<NOTIF_BODY>
<UserDetail>
<USER_NAME>Mr Customer</USER_NAME>
<USER_EMAIL>MrCustomer@email.com</USER_EMAIL>
<USER_MO>0500000007</USER_MO>
</UserDetail>
<CAS_Token>
<PASS>
<![CDATA[[PASS]]]>
</PASS>
<GEMALTO>N</GEMALTO>
</CAS_Token>
</NOTIF_BODY>
</NOTIFICATION>
我想序列化这个xml。为此我尝试创建模型类,但没有工作。
答案 0 :(得分:1)
这是你的班级:
/// <remarks/>
[System.Xml.Serialization.XmlTypeAttribute(AnonymousType = true)]
[System.Xml.Serialization.XmlRootAttribute(Namespace = "", IsNullable = false)]
public partial class NOTIFICATION
{
private NOTIFICATIONNOTIF_HEADER nOTIF_HEADERField;
private NOTIFICATIONNOTIF_BODY nOTIF_BODYField;
/// <remarks/>
public NOTIFICATIONNOTIF_HEADER NOTIF_HEADER
{
get
{
return this.nOTIF_HEADERField;
}
set
{
this.nOTIF_HEADERField = value;
}
}
/// <remarks/>
public NOTIFICATIONNOTIF_BODY NOTIF_BODY
{
get
{
return this.nOTIF_BODYField;
}
set
{
this.nOTIF_BODYField = value;
}
}
}
/// <remarks/>
[System.Xml.Serialization.XmlTypeAttribute(AnonymousType = true)]
public partial class NOTIFICATIONNOTIF_HEADER
{
private string sOURCEField;
private ulong mSGIDField;
private string tXN_IDField;
/// <remarks/>
public string SOURCE
{
get
{
return this.sOURCEField;
}
set
{
this.sOURCEField = value;
}
}
/// <remarks/>
public ulong MSGID
{
get
{
return this.mSGIDField;
}
set
{
this.mSGIDField = value;
}
}
/// <remarks/>
public string TXN_ID
{
get
{
return this.tXN_IDField;
}
set
{
this.tXN_IDField = value;
}
}
}
/// <remarks/>
[System.Xml.Serialization.XmlTypeAttribute(AnonymousType = true)]
public partial class NOTIFICATIONNOTIF_BODY
{
private NOTIFICATIONNOTIF_BODYUserDetail userDetailField;
private NOTIFICATIONNOTIF_BODYCAS_Token cAS_TokenField;
/// <remarks/>
public NOTIFICATIONNOTIF_BODYUserDetail UserDetail
{
get
{
return this.userDetailField;
}
set
{
this.userDetailField = value;
}
}
/// <remarks/>
public NOTIFICATIONNOTIF_BODYCAS_Token CAS_Token
{
get
{
return this.cAS_TokenField;
}
set
{
this.cAS_TokenField = value;
}
}
}
/// <remarks/>
[System.Xml.Serialization.XmlTypeAttribute(AnonymousType = true)]
public partial class NOTIFICATIONNOTIF_BODYUserDetail
{
private string uSER_NAMEField;
private string uSER_EMAILField;
private uint uSER_MOField;
/// <remarks/>
public string USER_NAME
{
get
{
return this.uSER_NAMEField;
}
set
{
this.uSER_NAMEField = value;
}
}
/// <remarks/>
public string USER_EMAIL
{
get
{
return this.uSER_EMAILField;
}
set
{
this.uSER_EMAILField = value;
}
}
/// <remarks/>
public uint USER_MO
{
get
{
return this.uSER_MOField;
}
set
{
this.uSER_MOField = value;
}
}
}
/// <remarks/>
[System.Xml.Serialization.XmlTypeAttribute(AnonymousType = true)]
public partial class NOTIFICATIONNOTIF_BODYCAS_Token
{
private string pASSField;
private string gEMALTOField;
/// <remarks/>
public string PASS
{
get
{
return this.pASSField;
}
set
{
this.pASSField = value;
}
}
/// <remarks/>
public string GEMALTO
{
get
{
return this.gEMALTOField;
}
set
{
this.gEMALTOField = value;
}
}
}
您可以使用VS生成自己:
修改 - &gt; 选择性粘贴 - &gt; 将XML粘贴为类