xml一般操作

2021-09-09 05:11:13 字數 997 閱讀 7353

讀xml內容 

xmldocument xml = new xmldocument();

xml.loadxml(ret);

xmlnode node = xml.selectsinglenode(「//ex_message//ex_devip」);

if (node == null)

寫xml內容

xmldocument xmldoc = new xmldocument();

//描述

xmldeclaration xmldec = xmldoc.createxmldeclaration("1.0", "utf-8", null);

//根節點

xmlnode rootnode = xmldoc.createelement("ex_message");

//報文頭

string dtnow = datetime.now.tostring("yyyymmddhhmmss");

xmlnode node = xmldoc.createelement("ex_trtime");

node.innertext = dtnow;

string ret = xmldoc.innerxml;//得到xml字串

xml內容轉成實體類的通用函式,要求xml節點名和實體類屬性名稱一致:

public static listgetinnertexts(xmldocument xml, string xpath) where t : new()

listobjs = new list();

t obj;

type type = typeof(t);

//遍歷迴圈節點內容

foreach (xmlelement ele in nodes)

objs.add(obj);

}return objs;

}

c 操作xml一般通用的範例

using system using system.collections using system.componentmodel using system.data using system.drawing using system.web using system.web.sessionstat...

c 操作xml一般通用的範例

using system using system.collections using system.componentmodel using system.data using system.drawing using system.web using system.web.sessionstat...

LINUX 一般操作命令

linux 一般操作命令 本人用linux 時候也不算長,不到3個月吧,這裡把這三個月裡所學的一些操作常用命令做乙個總結 一 一些相關的命令 ls 列出檔案,檔名 cp 檔案的複製 rm 刪除檔案 rm r 刪除有檔案的資料夾 mv 移動檔案 mkdir 建立目錄 rmdir 刪除目錄 ps 檢視程...