C# xmlSerializer簡單用法示例
本文實(shí)例講述了C# xmlSerializer簡單用法。分享給大家供大家參考,具體如下:
先上實(shí)體類
public class Entity
{
public Entity()
{
}
public Entity(string c, string f)
{
name = c;
school = f;
}
public string name;
public string school;
}
使用時(shí)聲明
List<Entity> entityList=null; XmlSerializer xs = new XmlSerializer(typeof(List<Entity>));
讀入
using (StreamReader sr = new StreamReader(configPath))
{
entityList = xs.Deserialize(sr) as List<Entity>;
}
輸出
using (StreamWriter sw = File.CreateText(configPath))
{
xs.Serialize(sw, entityList);
}
對(duì)應(yīng)的xml
<?xml version="1.0" encoding="utf-8"?> <ArrayOfEntity xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"> <Entity> <Name>Alice</Name> <School>SJTU</School> </Entity> <Entity> <Name>Cici</Name> <School>CSU</School> </Entity> <Entity> <Name>Zero</Name> <School>HIT</School> </Entity> </ArrayOfEntity>
PS:這里再為大家提供幾款比較實(shí)用的xml相關(guān)在線工具供大家使用:
在線XML格式化/壓縮工具:
http://tools.jb51.net/code/xmlformat
在線XML/JSON互相轉(zhuǎn)換工具:
http://tools.jb51.net/code/xmljson
XML在線壓縮/格式化工具:
http://tools.jb51.net/code/xml_format_compress
XML代碼在線格式化美化工具:
http://tools.jb51.net/code/xmlcodeformat
更多關(guān)于C#相關(guān)內(nèi)容感興趣的讀者可查看本站專題:《C#中XML文件操作技巧匯總》、《C#常見控件用法教程》、《C#程序設(shè)計(jì)之線程使用技巧總結(jié)》、《WinForm控件用法總結(jié)》、《C#數(shù)據(jù)結(jié)構(gòu)與算法教程》、《C#數(shù)組操作技巧總結(jié)》及《C#面向?qū)ο蟪绦蛟O(shè)計(jì)入門教程》
希望本文所述對(duì)大家C#程序設(shè)計(jì)有所幫助。
您可能感興趣的文章
- 01-10C#實(shí)現(xiàn)簡單的Login窗口實(shí)例
- 01-10Winform消除button按下出現(xiàn)的虛線簡單實(shí)現(xiàn)方法
- 01-10C#線程隊(duì)列用法實(shí)例分析
- 01-10winform簡單緩存類實(shí)例
- 01-10C#一個(gè)簡單的定時(shí)小程序?qū)崿F(xiàn)代碼
- 01-10C#圓角窗體簡單實(shí)現(xiàn)方法
- 01-10C#使用Mutex簡單實(shí)現(xiàn)程序單實(shí)例運(yùn)行的方法
- 01-10C#實(shí)現(xiàn)簡單合并word文檔的方法
- 01-10C#簡單實(shí)現(xiàn)子窗體向父窗體傳值的方法
- 01-10C#中Socket通信用法實(shí)例詳解


閱讀排行
本欄相關(guān)
- 01-10C#通過反射獲取當(dāng)前工程中所有窗體并
- 01-10關(guān)于ASP網(wǎng)頁無法打開的解決方案
- 01-10WinForm限制窗體不能移到屏幕外的方法
- 01-10WinForm繪制圓角的方法
- 01-10C#實(shí)現(xiàn)txt定位指定行完整實(shí)例
- 01-10WinForm實(shí)現(xiàn)仿視頻播放器左下角滾動(dòng)新
- 01-10C#停止線程的方法
- 01-10C#實(shí)現(xiàn)清空回收站的方法
- 01-10C#通過重寫Panel改變邊框顏色與寬度的
- 01-10C#實(shí)現(xiàn)讀取注冊(cè)表監(jiān)控當(dāng)前操作系統(tǒng)已
隨機(jī)閱讀
- 01-11ajax實(shí)現(xiàn)頁面的局部加載
- 01-11Mac OSX 打開原生自帶讀寫NTFS功能(圖文
- 08-05織夢(mèng)dedecms什么時(shí)候用欄目交叉功能?
- 04-02jquery與jsp,用jquery
- 01-10SublimeText編譯C開發(fā)環(huán)境設(shè)置
- 01-10使用C語言求解撲克牌的順子及n個(gè)骰子
- 08-05dedecms(織夢(mèng))副欄目數(shù)量限制代碼修改
- 08-05DEDE織夢(mèng)data目錄下的sessions文件夾有什
- 01-10C#中split用法實(shí)例總結(jié)
- 01-10delphi制作wav文件的方法


