資源簡介
實(shí)現(xiàn)了對xml文件的讀寫
代碼片段和文件信息
using?System;
using?System.Collections.Generic;
using?System.Linq;
using?System.Web;
using?System.IO;
using?System.xml;
using?System.Data;
namespace?Phone
{
????///?
????///xmlProcess?的摘要說明
????///?
????public?class?xmlProcess
????{
????????public?xmlProcess()
????????{
????????????//
????????????//TODO:?在此處添加構(gòu)造函數(shù)邏輯
????????????//
????????}
????????public?xmlProcess(string?strPath)
????????{
????????????this._xmlPath?=?strPath;
????????}
????????private?string?_xmlPath;
????????public?string?xmlPath
????????{
????????????get?{?return?this._xmlPath;?}
????????}
????????///?
????????///?導(dǎo)入xml文件
????????///?
????????///?lPath“>xml文件路徑
????????///?
????????private?xmlDocument?xmlLoad()
????????{
????????????string?xmlFile?=?xmlPath;
????????????xmlDocument?xmldoc?=?new?xmlDocument();
????????????try
????????????{
????????????????string?filename?=?AppDomain.CurrentDomain.baseDirectory.ToString()?+?xmlFile;
????????????????if?(File.Exists(filename))
????????????????????xmldoc.Load(filename);
????????????}
????????????catch?(Exception?e)
????????????{
????????????????throw?e;
????????????}
????????????return?xmldoc;
????????}
????????///?
????????///?導(dǎo)入xml文件
????????///?
????????///?lPath“>xml文件路徑
????????///?
????????private?static?xmlDocument?xmlLoad(string?strPath)
????????{
????????????xmlDocument?xmldoc?=?new?xmlDocument();
????????????try
????????????{
????????????????string?filename?=?AppDomain.CurrentDomain.baseDirectory.ToString()?+?strPath;
????????????????if?(File.Exists(filename))
????????????????????xmldoc.Load(filename);
????????????}
????????????catch?(Exception?e)
????????????{
????????????????throw?e;
????????????}
????????????return?xmldoc;
????????}
????????///?
????????///?讀取指定節(jié)點(diǎn)的數(shù)據(jù)
????????///?
????????///?節(jié)點(diǎn)
????????///?string
????????/**************************************************
?????????*?使用示列:
?????????*?xmlProsess.Read(“/Node“?““)
?????????*?xmlProsess.Read(“/Node/Element[@Attribute=‘Name‘]“)
?????????************************************************/
????????public?string?Read(string?node)
????????{
????????????string?value?=?““;
????????????try
????????????{
????????????????xmlDocument?doc?=?xmlLoad();
????????????????xmlNode?xn?=?doc.SelectSingleNode(node);
????????????????value?=?xn.InnerText;
????????????}
????????????catch?(Exception?e)?
????????????{
????????????????throw?e;
????????????}
????????????return?value;
????????}
????????///?
????????///?讀取指定路徑和節(jié)點(diǎn)的串聯(lián)值
????????///?
????????///?路徑
????????///?節(jié)點(diǎn)
????????///?屬性名,非空時(shí)返回該屬性值,否則返回串聯(lián)值
????????///?string
????????/********
?屬性????????????大小?????日期????時(shí)間???名稱
-----------?---------??----------?-----??----
?????文件??????16307??2020-03-03?15:11??xm
-----------?---------??----------?-----??----
????????????????16307????????????????????1
評論
共有 條評論