資源簡介
實現了對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:?在此處添加構造函數邏輯
????????????//
????????}
????????public?xmlProcess(string?strPath)
????????{
????????????this._xmlPath?=?strPath;
????????}
????????private?string?_xmlPath;
????????public?string?xmlPath
????????{
????????????get?{?return?this._xmlPath;?}
????????}
????????///?
????????///?導入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;
????????}
????????///?
????????///?導入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;
????????}
????????///?
????????///?讀取指定節點的數據
????????///?
????????///?節點
????????///?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;
????????}
????????///?
????????///?讀取指定路徑和節點的串聯值
????????///?
????????///?路徑
????????///?節點
????????///?屬性名,非空時返回該屬性值,否則返回串聯值
????????///?string
????????/********
?屬性????????????大小?????日期????時間???名稱
-----------?---------??----------?-----??----
?????文件??????16307??2020-03-03?15:11??xm
-----------?---------??----------?-----??----
????????????????16307????????????????????1
- 上一篇:文件內容比較(附高亮)
- 下一篇:借助WPS將Word文檔轉換為PPT文檔
評論
共有 條評論