最近在做c# 乙個專案,涉及到序列化知識點,但對於複雜的xml格式不知道如何編寫實體類,網上也沒找到相同型別格式的xml介紹的部落格資料,所以研究了兩天,終於做出來了,先把xml格式的字串貼上來。
cw201906271117030642
030.0
15000119230104170217
15000119230104170217
中國杭州西湖區龍井路002號
gwyy001
kwyy001
99.9
909.9 2
1030111020水果
kk1100100
0.11111
1030111020水果
-100.11
-1.1
實體類**:
namespace cw.hf.his.test
= "request_common_fpkj";
private common_fpkj_fpt commonfpkjfpt = null;
//屬性的定義
[xmlelement("common_fpkj_fpt")]
public common_fpkj_fpt common_fpkj_fpt
return commonfpkjfpt;
}set
}private common_fpkj_xmxxs commonfpkjxmxxs = null;
[xmlelement("common_fpkj_xmxxs")]
public common_fpkj_xmxxs common_fpkj_xmxxs
return commonfpkjxmxxs;
}set }}
public class common_fpkj_fpt
= "common_fpkj_fpt";
[xmlelement("fpqqlsh")]
public string fpqqlsh = string.empty;
[xmlelement("ddh")]
public string ddh
= string.empty;
[xmlelement("kplx")]
public string kplx
= string.empty;
[xmlelement("bmb_bbh")]
public string bmb_bbh = string.empty;
[xmlelement("xsf_nsrsbh")]
public string xsf_nsrsbh
= string.empty;
[xmlelement("xsf_mc")]
public string xsf_mc
= string.empty;
[xmlelement("xsf_dzdh")]
public string xsf_dzdh = string.empty;
[xmlelement("xsf_yhzh")]
public string xsf_yhzh
= string.empty;
[xmlelement("gmf_nsrsbh")]
public string gmf_nsrsbh
= string.empty;
[xmlelement("gmf_mc")]
public string gmf_mc = string.empty;
[xmlelement("gmf_dzdh")]
public string gmf_dzdh
= string.empty;
[xmlelement("gmf_yhzh")]
public string gmf_yhzh
= string.empty;
[xmlelement("gmf_sj")]
public string gmf_sj
= string.empty;
[xmlelement("gmf_email")]
public string gmf_email
= string.empty;
[xmlelement("kpr")]
public string kpr
= string.empty;
[xmlelement("skr")]
public string skr
= string.empty;
[xmlelement("fhr")]
public string fhr
= string.empty;
[xmlelement("yfp_dm")]
public string yfp_dm
= string.empty;
[xmlelement("yfp_hm")]
public string yfp_hm
= string.empty;
[xmlelement("jshj")]
public string jshj
= string.empty;
[xmlelement("hjje")]
public string hjje
= string.empty;
[xmlelement("hjse")]
public string hjse
= string.empty;
[xmlelement("bz")]
public string bz
= string.empty;
}public class common_fpkj_xmxxs
= "common_fpkj_xmxx";
[xmlattribute("size")]
public string size
private listcommonfpkjxmxxs = null;
[xmlelement("common_fpkj_xmxx")]
public listfpkj_xmxxs
return commonfpkjxmxxs;
}set }}
public class common_fpkj_xmxx
= string.empty;
[xmlelement("spbm")]
public string spbm = string.empty;
[xmlelement("zxbm")]
public string zxbm = string.empty;
[xmlelement("yhzcbs")]
public string yhzcbs = string.empty;
[xmlelement("lslbs")]
public string lslbs = string.empty;
[xmlelement("zzstsgl")]
public string zzstsgl = string.empty;
[xmlelement("xmmc")]
public string xmmc = string.empty;
[xmlelement("ggxh")]
public string ggxh = string.empty;
[xmlelement("dw")]
public string dw = string.empty;
[xmlelement("xmsl")]
public string xmsl = string.empty;
[xmlelement("xmdj")]
public string xmdj = string.empty;
[xmlelement("xmje")]
public string xmje = string.empty;
[xmlelement("sl")]
public string sl = string.empty;
[xmlelement("se")]
public string se = string.empty;}}
反序列化和序列化**網上多的時,就不一 一貼上了
下面是序列化**,檔案頭部結果不包含xmlns:xsi="" xmlns:xsd=""
///
/// 序列化
///
///
///
public static string serializexml(object data)
}下面是另一種序列化**,檔案頭部結果包含xmlns:xsi="" xmlns:xsd=""
public static string serializer(type type, object obj)
c xml字串 反序列化為例項物件
xml格式字串,反序列化為例項物件需要注意的項 1 xml的root節點跟類的名字要一致 2,xml子節點要與類的成員名字要一致 3,xml字串前要加 下面是乙個小例子 string xmlstr 5002 00001 1002014.10.27 mary jiankangka 666666 xml...
c XML序列化與反序列化
序列化物件 public class people xmlattribute age public int age xmlroot root public class student people xmlelement number public int number void main strin...
c 將物件序列化為字串和將字串反序列化為物件
using system using system.runtime.serialization using system.runtime.serialization.formatters.binary using system.io serializeutilities 的摘要說明 public c...