[No0000DE]C# XmlHelper XML类型操作 类封装
using System;
using System.Data;
using System.IO;
using System.Text;
using System.Threading;
using System.Xml;
using System.Xml.Serialization;
using Shared; namespace Helpers
{
public static class XmlHelper
{
#region Fields and Properties public enum XmlType
{
File,
String
} #endregion #region Methods /// <summary>
/// 创建XML文档
/// </summary>
/// <param name="name">根节点名称</param>
/// <param name="type">根节点的一个属性值</param>
/// <returns></returns>
public static XmlDocument CreateXmlDocument(string name, string type)
{
/**************************************************
* .net中调用方法:写入文件中,则:
*document = XmlOperate.CreateXmlDocument("sex", "sexy");
*document.Save("c:/bookstore.xml");
************************************************/
XmlDocument xmlDocument;
try
{
xmlDocument = new XmlDocument();
xmlDocument.LoadXml("<" + name + "/>");
var rootElement = xmlDocument.DocumentElement;
rootElement?.SetAttribute("type", type);
}
catch (Exception exception)
{
LogHelper.LogError("Error! ", exception);
return null;
}
return xmlDocument;
} /// <summary>
/// 删除数据
/// </summary>
/// <param name="path">路径</param>
/// <param name="node">节点</param>
/// <param name="attribute">属性名,非空时删除该节点属性值,否则删除节点值</param>
/// <returns></returns>
public static void Delete(string path, string node, string attribute)
{
/**************************************************
* 使用示列:
* XmlHelper.Delete(path, "/Node", "")
* XmlHelper.Delete(path, "/Node", "Attribute")
************************************************/
try
{
var xmlDocument = new XmlDocument();
xmlDocument.Load(path);
var selectSingleNode = xmlDocument.SelectSingleNode(node);
var xmlElement = (XmlElement) selectSingleNode;
if (attribute.Equals(""))
selectSingleNode?.ParentNode?.RemoveChild(selectSingleNode);
else
xmlElement?.RemoveAttribute(attribute);
xmlDocument.Save(path);
}
catch (Exception exception)
{
LogHelper.LogError("Error! ", exception);
}
} /// <summary>
/// 读取XML资源到DataSet中
/// </summary>
/// <param name="source">XML资源,文件为路径,否则为XML字符串</param>
/// <param name="xmlType">XML资源类型</param>
/// <returns>DataSet</returns>
public static DataSet GetDataSet(string source, XmlType xmlType)
{
try
{
var dataSet = new DataSet();
if (xmlType == XmlType.File)
{
dataSet.ReadXml(source);
}
else
{
var xmlDocument = new XmlDocument();
xmlDocument.LoadXml(source);
var xmlNodeReader = new XmlNodeReader(xmlDocument);
dataSet.ReadXml(xmlNodeReader);
}
return dataSet;
}
catch (Exception exception)
{
LogHelper.LogError("Error! ", exception);
return null;
}
} /// <summary>
/// 获得xml文件中指定节点的节点数据
/// </summary>
/// <returns></returns>
public static string GetNodeInfoByNodeName(string path, string nodeName)
{
try
{
var xmlString = "";
var xmlDocument = new XmlDocument();
xmlDocument.Load(path);
var documentElementRoot = xmlDocument.DocumentElement;
var selectSingleNode = documentElementRoot?.SelectSingleNode("//" + nodeName);
if (selectSingleNode != null)
xmlString = selectSingleNode.InnerText;
return xmlString;
}
catch (Exception exception)
{
LogHelper.LogError("Error! ", exception);
return null;
}
} /// <summary>
/// 读取XML资源中的指定节点内容
/// </summary>
/// <param name="source">XML资源</param>
/// <param name="xmlType">XML资源类型:文件,字符串</param>
/// <param name="nodeName">节点名称</param>
/// <returns>节点内容</returns>
public static string GetNodeValue(string source, XmlType xmlType, string nodeName)
{
var xmlDocument = new XmlDocument();
if (xmlType == XmlType.File)
xmlDocument.Load(source);
else
xmlDocument.LoadXml(source);
var documentElement = xmlDocument.DocumentElement;
var selectSingleNode = documentElement?.SelectSingleNode("//" + nodeName);
return selectSingleNode?.InnerText;
} /// <summary>
/// 读取XML资源中的指定节点属性的内容
/// </summary>
/// <param name="source">XML资源</param>
/// <param name="xmlType">XML资源类型:文件,字符串</param>
/// <param name="nodeName">属性节点名称</param>
/// <param name="attributeString"></param>
/// <returns>节点内容</returns>
public static string GetNodeAttributeValue(string source, XmlType xmlType, string nodeName,
string attributeString)
{
var xmlDocument = new XmlDocument();
if (xmlType == XmlType.File)
xmlDocument.Load(source);
else
xmlDocument.LoadXml(source);
var documentElement = xmlDocument.DocumentElement;
var selectSingleNode = (XmlElement) documentElement?.SelectSingleNode("//" + nodeName);
//if (selectSingleNode != null)
return selectSingleNode?.GetAttribute(attributeString);
} /// <summary>
/// 读取XML资源中的指定节点内容
/// </summary>
/// <param name="source">XML资源</param>
/// <param name="nodeName">节点名称</param>
/// <returns>节点内容</returns>
public static string GetNodeValue(string source, string nodeName)
{
if (source == null || nodeName == null || source == "" || nodeName == "" ||
source.Length < nodeName.Length * )
return null;
var start = source.IndexOf("<" + nodeName + ">", StringComparison.Ordinal) + nodeName.Length + ;
var end = source.IndexOf("</" + nodeName + ">", StringComparison.Ordinal);
if (start == - || end == -)
return null;
return start >= end ? null : source.Substring(start, end - start);
} /// <summary>
/// 读取XML资源到DataTable中
/// </summary>
/// <param name="source">XML资源,文件为路径,否则为XML字符串</param>
/// <param name="xmlType">XML资源类型:文件,字符串</param>
/// <param name="tableName">表名称</param>
/// <returns>DataTable</returns>
public static DataTable GetTable(string source, XmlType xmlType, string tableName)
{
try
{
var dataSet = new DataSet();
if (xmlType == XmlType.File)
{
dataSet.ReadXml(source);
}
else
{
var xmlDocument = new XmlDocument();
xmlDocument.LoadXml(source);
var xmlNodeReader = new XmlNodeReader(xmlDocument);
dataSet.ReadXml(xmlNodeReader);
}
return dataSet.Tables[tableName];
}
catch (Exception exception)
{
LogHelper.LogError("Error! ", exception);
return null;
}
} /// <summary>
/// 读取XML资源中指定的DataTable的指定行指定列的值
/// </summary>
/// <param name="source">XML资源</param>
/// <param name="xmlType">XML资源类型:文件,字符串</param>
/// <param name="tableName">表名</param>
/// <param name="rowIndex">行号</param>
/// <param name="colName">列名</param>
/// <returns>值,不存在时返回Null</returns>
public static object GetTableCell(string source, XmlType xmlType, string tableName, int rowIndex, string colName)
{
try
{
var dataSet = new DataSet();
if (xmlType == XmlType.File)
{
dataSet.ReadXml(source);
}
else
{
var xmlDocument = new XmlDocument();
xmlDocument.LoadXml(source);
var xmlNodeReader = new XmlNodeReader(xmlDocument);
dataSet.ReadXml(xmlNodeReader);
}
return dataSet.Tables[tableName].Rows[rowIndex][colName];
}
catch (Exception exception)
{
LogHelper.LogError("Error! ", exception);
return null;
}
} /// <summary>
/// 读取XML资源中指定的DataTable的指定行指定列的值
/// </summary>
/// <param name="source">XML资源</param>
/// <param name="xmlType">XML资源类型:文件,字符串</param>
/// <param name="tableName">表名</param>
/// <param name="rowIndex">行号</param>
/// <param name="colIndex">列号</param>
/// <returns>值,不存在时返回Null</returns>
public static object GetTableCell(string source, XmlType xmlType, string tableName, int rowIndex, int colIndex)
{
try
{
var dataSet = new DataSet();
if (xmlType == XmlType.File)
{
dataSet.ReadXml(source);
}
else
{
var xmlDocument = new XmlDocument();
xmlDocument.LoadXml(source);
var xmlNodeReader = new XmlNodeReader(xmlDocument);
dataSet.ReadXml(xmlNodeReader);
}
return dataSet.Tables[tableName].Rows[rowIndex][colIndex];
}
catch (Exception exception)
{
LogHelper.LogError("Error! ", exception);
return null;
}
} /// <summary>
/// 获取一个字符串xml文档中的dataSet
/// </summary>
/// <param name="xmlString">含有xml信息的字符串</param>
/// <param name="dataSet"></param>
public static void GetXmlValueDataSet(string xmlString, ref DataSet dataSet)
{
try
{
var xmlDocument = new XmlDocument();
xmlDocument.LoadXml(xmlString);
var xmlNodeReader = new XmlNodeReader(xmlDocument);
dataSet.ReadXml(xmlNodeReader);
xmlNodeReader.Close();
}
catch (Exception exception)
{
LogHelper.LogError("Error! ", exception);
}
} /// <summary>
/// 插入数据
/// </summary>
/// <param name="path">路径</param>
/// <param name="node">节点</param>
/// <param name="element">元素名,非空时插入新元素,否则在该元素中插入属性</param>
/// <param name="attribute">属性名,非空时插入该元素属性值,否则插入元素值</param>
/// <param name="value">值</param>
/// <returns></returns>
public static void Insert(string path, string node, string element, string attribute, string value)
{
/**************************************************
* 使用示列:
* XmlHelper.Insert(path, "/Node", "Element", "", "Value")
* XmlHelper.Insert(path, "/Node", "Element", "Attribute", "Value")
* XmlHelper.Insert(path, "/Node", "", "Attribute", "Value")
************************************************/
try
{
var xmlDocument = new XmlDocument();
xmlDocument.Load(path);
var selectSingleNode = xmlDocument.SelectSingleNode(node);
if (element.Equals(""))
{
if (!attribute.Equals(""))
{
var xmlElement = (XmlElement) selectSingleNode;
xmlElement?.SetAttribute(attribute, value);
}
}
else
{
var xmlElement = xmlDocument.CreateElement(element);
if (attribute.Equals(""))
xmlElement.InnerText = value;
else
xmlElement.SetAttribute(attribute, value);
selectSingleNode?.AppendChild(xmlElement);
}
xmlDocument.Save(path);
}
catch (Exception exception)
{
LogHelper.LogError("Error! ", exception);
}
} /// <summary>
/// 读取数据
/// </summary>
/// <param name="path">路径</param>
/// <param name="node">节点</param>
/// <param name="attribute">属性名,非空时返回该属性值,否则返回串联值</param>
/// <returns>string</returns>
public static string Read(string path, string node, string attribute)
{
/**************************************************
* 使用示列:
* XmlHelper.Read(path, "/Node", "")
* XmlHelper.Read(path, "/Node/Element[@Attribute='Name']", "Attribute")
************************************************/
var value = "";
try
{
var xmlDocument = new XmlDocument();
xmlDocument.Load(path);
var selectSingleNode = xmlDocument.SelectSingleNode(node);
value = attribute.Equals("")
? selectSingleNode?.InnerText
: selectSingleNode?.Attributes?[attribute].Value;
}
catch (Exception exception)
{
LogHelper.LogError("Error! ", exception);
}
return value;
} /// <summary>
/// 读取xml的节点
/// </summary>
/// <param name="path">路径</param>
/// <param name="nodeName">节点名称</param>
/// <param name="name">属性名称</param>
/// <returns></returns>
public static string ReadXml(string path, string nodeName, string name) //读取XML
{
try
{
var xmlValue = "";
if (!File.Exists(path))
return xmlValue;
var myFile = new FileStream(path, FileMode.Open); //打开xml文件
var xmlTextReader = new XmlTextReader(myFile); //xml文件阅读器
while (xmlTextReader.Read())
if (xmlTextReader.Name == nodeName)
{
//获取服务器的地址//获取升级文档的最后一次更新日期
xmlValue = xmlTextReader.GetAttribute(name);
break;
}
xmlTextReader.Close();
myFile.Close();
return xmlValue;
}
catch (Exception exception)
{
LogHelper.LogError("Error! ", exception);
return null;
}
} /// <summary>
/// 读取xml文件,并将文件序列化为类
/// </summary>
/// <typeparam name="T"></typeparam>
/// <param name="path"></param>
/// <returns></returns>
public static T ReadXML<T>(string path)
{
try
{
var reader = new XmlSerializer(typeof(T));
var file = new StreamReader(path);
return (T) reader.Deserialize(file);
}
catch (Exception exception)
{
LogHelper.LogError("Error! ", exception);
return default(T);
}
} /// <summary>
/// 将DataTable写入XML文件中
/// </summary>
/// <param name="dataTable">含有数据的DataTable</param>
/// <param name="filePath">文件路径</param>
public static void SaveTableToFile(DataTable dataTable, string filePath)
{
try
{
var dataSet = new DataSet("Config");
dataSet.Tables.Add(dataTable.Copy());
dataSet.WriteXml(filePath);
}
catch (Exception exception)
{
LogHelper.LogError("Error! ", exception);
}
} /// <summary>
/// 将DataTable以指定的根结点名称写入文件
/// </summary>
/// <param name="dataTable">含有数据的DataTable</param>
/// <param name="rootName">根结点名称</param>
/// <param name="filePath">文件路径</param>
public static void SaveTableToFile(DataTable dataTable, string rootName, string filePath)
{
try
{
var dataSet = new DataSet(rootName);
dataSet.Tables.Add(dataTable.Copy());
dataSet.WriteXml(filePath);
}
catch (Exception exception)
{
LogHelper.LogError("Error! ", exception);
}
} /// <summary>
/// 静态扩展
/// </summary>
/// <typeparam name="T">需要序列化的对象类型,必须声明[Serializable]特征</typeparam>
/// <param name="obj">需要序列化的对象</param>
/// <param name="omitXmlDeclaration">true:省略XML声明;否则为false.默认false,即编写 XML 声明。</param>
/// <returns></returns>
public static string SerializeToXmlStr<T>(T obj, bool omitXmlDeclaration)
{
try
{
return XmlSerialize(obj, omitXmlDeclaration);
}
catch (Exception exception)
{
LogHelper.LogError("Error! ", exception);
return null;
}
} /// <summary>
/// 修改数据
/// </summary>
/// <param name="path">路径</param>
/// <param name="node">节点</param>
/// <param name="attribute">属性名,非空时修改该节点属性值,否则修改节点值</param>
/// <param name="value">值</param>
/// <returns></returns>
public static void Update(string path, string node, string attribute, string value)
{
/**************************************************
* 使用示列:
* XmlHelper.Insert(path, "/Node", "", "Value")
* XmlHelper.Insert(path, "/Node", "Attribute", "Value")
************************************************/
try
{
var xmlDocument = new XmlDocument();
xmlDocument.Load(path);
var selectSingleNode = xmlDocument.SelectSingleNode(node);
var xmlElement = (XmlElement) selectSingleNode;
if (attribute.Equals(""))
{
if (xmlElement != null) xmlElement.InnerText = value;
}
else
{
xmlElement?.SetAttribute(attribute, value);
}
xmlDocument.Save(path);
}
catch (Exception exception)
{
LogHelper.LogError("Error! ", exception);
}
} /// <summary>
/// 更新XML文件中的指定节点内容
/// </summary>
/// <param name="filePath">文件路径</param>
/// <param name="nodeName">节点名称</param>
/// <param name="nodeValue">更新内容</param>
/// <returns>更新是否成功</returns>
public static bool UpdateNode(string filePath, string nodeName, string nodeValue)
{
bool flag; var xmlDocument = new XmlDocument();
xmlDocument.Load(filePath);
var documentElement = xmlDocument.DocumentElement;
var selectSingleNode = documentElement?.SelectSingleNode("//" + nodeName);
if (selectSingleNode != null)
{
selectSingleNode.InnerText = nodeValue;
flag = true;
}
else
{
flag = false;
}
return flag;
} /// <summary>
/// 使用DataSet方式更新XML文件节点
/// </summary>
/// <param name="filePath">XML文件路径</param>
/// <param name="tableName">表名称</param>
/// <param name="rowIndex">行号</param>
/// <param name="colName">列名</param>
/// <param name="content">更新值</param>
/// <returns>更新是否成功</returns>
public static bool UpdateTableCell(string filePath, string tableName, int rowIndex, string colName,
string content)
{
bool flag;
var dataSet = new DataSet();
dataSet.ReadXml(filePath);
var dataTable = dataSet.Tables[tableName]; if (dataTable.Rows[rowIndex][colName] != null)
{
dataTable.Rows[rowIndex][colName] = content;
dataSet.WriteXml(filePath);
flag = true;
}
else
{
flag = false;
}
return flag;
} /// <summary>
/// 使用DataSet方式更新XML文件节点
/// </summary>
/// <param name="filePath">XML文件路径</param>
/// <param name="tableName">表名称</param>
/// <param name="rowIndex">行号</param>
/// <param name="colIndex">列号</param>
/// <param name="content">更新值</param>
/// <returns>更新是否成功</returns>
public static bool UpdateTableCell(string filePath, string tableName, int rowIndex, int colIndex, string content)
{
bool flag; var dataSet = new DataSet();
dataSet.ReadXml(filePath);
var dataTable = dataSet.Tables[tableName]; if (dataTable.Rows[rowIndex][colIndex] != null)
{
dataTable.Rows[rowIndex][colIndex] = content;
dataSet.WriteXml(filePath);
flag = true;
}
else
{
flag = false;
}
return flag;
} /// <summary>
/// 将对象写入XML文件
/// </summary>
/// <typeparam name="T">C#对象名</typeparam>
/// <param name="item">对象实例</param>
/// <param name="path">路径</param>
/// <param name="jjdbh">标号</param>
/// <param name="ends">结束符号(整个xml的路径类似如下:C:\xmltest\201111send.xml,其中path=C:\xmltest,jjdbh=201111,ends=send)</param>
/// <returns></returns>
public static string WriteXML<T>(T item, string path, string jjdbh, string ends)
{
if (string.IsNullOrEmpty(ends))
ends = "send";
var i = ; //控制写入文件的次数,
var serializer = new XmlSerializer(item.GetType());
object[] obj = {path, "\\", jjdbh, ends, ".xml"};
var xmlPath = string.Concat(obj);
while (true)
try
{
var fileStream = File.Create(xmlPath); //用filestream方式创建文件不会出现“文件正在占用中,用File.create”则不行
fileStream.Close();
TextWriter writer = new StreamWriter(xmlPath, false, Encoding.UTF8);
var xmlSerializerNamespaces = new XmlSerializerNamespaces();
xmlSerializerNamespaces.Add(string.Empty, string.Empty);
serializer.Serialize(writer, item, xmlSerializerNamespaces);
writer.Flush();
writer.Close();
break;
}
catch (Exception exception)
{
if (i < )
i++;
else
{
LogHelper.LogError("Error! ", exception);
break;
}
}
return SerializeToXmlStr(item, true);
} /// <summary>
/// 使用XmlSerializer反序列化对象
/// </summary>
/// <param name="xmlOfObject">需要反序列化的xml字符串</param>
/// <returns>反序列化后的对象</returns>
public static T XmlDeserialize<T>(string xmlOfObject) where T : class
{
var xmlReader = XmlReader.Create(new StringReader(xmlOfObject), new XmlReaderSettings());
return (T) new XmlSerializer(typeof(T)).Deserialize(xmlReader);
} /// <summary>
/// 从文件读取并反序列化为对象 (解决: 多线程或多进程下读写并发问题)
/// </summary>
/// <typeparam name="T">返回的对象类型</typeparam>
/// <param name="path">文件地址</param>
/// <returns></returns>
public static T XmlFileDeserialize<T>(string path)
{
var bytes = ShareReadFile(path);
if (bytes.Length < ) //当文件正在被写入数据时,可能读出为0
for (var i = ; i < ; i++)
{
bytes = ShareReadFile(path); //5次机会,采用这样诡异的做法避免独占文件和文件正在被写入时读出来的数据为0字节的问题。
if (bytes.Length > ) break;
Thread.Sleep(); //悲观情况下总共最多消耗1/4秒,读取文件
}
var xmlDocument = new XmlDocument();
xmlDocument.Load(new MemoryStream(bytes));
if (xmlDocument.DocumentElement != null)
return (T) new XmlSerializer(typeof(T)).Deserialize(new XmlNodeReader(xmlDocument.DocumentElement));
return default(T);
/*var xmlReaderSettings = new XmlReaderSettings();
xmlReaderSettings.CloseInput = true;
using (var xmlReader = XmlReader.Create(path, xmlReaderSettings))
{
var obj = (T) new XmlSerializer(typeof(T)).Deserialize(xmlReader);
return obj;
}*/
} /// <summary>
/// 使用XmlSerializer序列化对象
/// </summary>
/// <typeparam name="T">需要序列化的对象类型,必须声明[Serializable]特征</typeparam>
/// <param name="obj">需要序列化的对象</param>
/// <param name="omitXmlDeclaration">true:省略XML声明;否则为false.默认false,即编写 XML 声明。</param>
/// <returns>序列化后的字符串</returns>
public static string XmlSerialize<T>(T obj, bool omitXmlDeclaration)
{
/* This property only applies to XmlWriter instances that output text content to a stream; otherwise, this setting is ignored.
可能很多朋友遇见过 不能转换成Xml不能反序列化成为UTF8XML声明的情况,就是这个原因。
*/
var xmlSettings = new XmlWriterSettings
{
OmitXmlDeclaration = omitXmlDeclaration,
Encoding = new UTF8Encoding(false)
};
var stream = new MemoryStream(); //var writer = new StringWriter();
var xmlwriter = XmlWriter.Create(stream /*writer*/, xmlSettings);
//这里如果直接写成:Encoding = Encoding.UTF8 会在生成的xml中加入BOM(Byte-order Mark) 信息(Unicode 字节顺序标记) , 所以new System.Text.UTF8Encoding(false)是最佳方式,省得再做替换的麻烦
var xmlSerializerNamespaces = new XmlSerializerNamespaces();
xmlSerializerNamespaces.Add(string.Empty, string.Empty); //在XML序列化时去除默认命名空间xmlns:xsd和xmlns:xsi
var xmlSerializer = new XmlSerializer(typeof(T));
xmlSerializer.Serialize(xmlwriter, obj, xmlSerializerNamespaces); return Encoding.UTF8.GetString(stream.ToArray()); //writer.ToString();
} /// <summary>
/// 使用XmlSerializer序列化对象
/// </summary>
/// <typeparam name="T"></typeparam>
/// <param name="path">文件路径</param>
/// <param name="obj">需要序列化的对象</param>
/// <param name="omitXmlDeclaration">true:省略XML声明;否则为false.默认false,即编写 XML 声明。</param>
/// <param name="removeDefaultNamespace">是否移除默认名称空间(如果对象定义时指定了:XmlRoot(Namespace = "http://www.xxx.com/xsd")则需要传false值进来)</param>
/// <returns>序列化后的字符串</returns>
public static void XmlSerialize<T>(string path, T obj, bool omitXmlDeclaration, bool removeDefaultNamespace)
{
var xmlWriterSettings = new XmlWriterSettings {OmitXmlDeclaration = omitXmlDeclaration};
using (var xmlWriter = XmlWriter.Create(path, xmlWriterSettings))
{
var xmlSerializerNamespaces = new XmlSerializerNamespaces();
if (removeDefaultNamespace)
xmlSerializerNamespaces.Add(string.Empty, string.Empty); //在XML序列化时去除默认命名空间xmlns:xsd和xmlns:xsi
var xmlSerializer = new XmlSerializer(typeof(T));
xmlSerializer.Serialize(xmlWriter, obj, xmlSerializerNamespaces);
}
} private static byte[] ShareReadFile(string filePath)
{
byte[] bytes;
//避免"正由另一进程使用,因此该进程无法访问此文件"造成异常 共享锁 flieShare必须为ReadWrite,但是如果文件不存在的话,还是会出现异常,所以这里不能吃掉任何异常,但是需要考虑到这些问题
using (var fileStream = new FileStream(filePath, FileMode.Open, FileAccess.Read, FileShare.ReadWrite))
{
bytes = new byte[fileStream.Length];
var numBytesToRead = (int) fileStream.Length;
var numBytesRead = ;
while (numBytesToRead > )
{
var bytesRead = fileStream.Read(bytes, numBytesRead, numBytesToRead);
if (bytesRead == )
break;
numBytesRead += bytesRead;
numBytesToRead -= bytesRead;
}
}
return bytes;
} #endregion
}
}
[No0000DE]C# XmlHelper XML类型操作 类封装的更多相关文章
- XML序列化 判断是否是手机 字符操作普通帮助类 验证数据帮助类 IO帮助类 c# Lambda操作类封装 C# -- 使用反射(Reflect)获取dll文件中的类型并调用方法 C# -- 文件的压缩与解压(GZipStream)
XML序列化 #region 序列化 /// <summary> /// XML序列化 /// </summary> /// <param name="ob ...
- Xml通用操作类
using System; using System.Collections.Generic; using System.IO; using System.Text; using System.Xml ...
- 基于 Aspose.Cells与XML导入excel 数据----操作类封装
前言 导入excel数据, 在每个项目中基本上都会遇到,第三方插件或者基于微软office,用的最多的就是npoi,aspose.cells和c#基于office这三种方式,其中各有各的优缺点,在这也 ...
- php-redis 操作类 封装
<?php /** * redis操作类 * 说明,任何为false的串,存在redis中都是空串. * 只有在key不存在时,才会返回false. * 这点可用于防止缓存穿透 * */ cla ...
- 【PHP+Redis】 php-redis 操作类 封装
<?php /** * redis操作类 * 说明,任何为false的串,存在redis中都是空串. * 只有在key不存在时,才会返回false. * 这点可用于防止缓存穿透 * */ cla ...
- C# XML文件操作类XmlHelper
类的完整代码: using System;using System.Collections;using System.Xml; namespace Keleyi.Com.XmlDAL{public c ...
- XML文件操作类--创建XML文件
这个类是在微软XML操作类库上进行的封装,只是为了更加简单使用,包括XML类创建节点的示例. using System; using System.Collections; using System. ...
- websql操作类封装
在之前,我写了一个websql的封装类库,代码如下: (function(win) { function smpWebSql(options){ options = options || {}; th ...
- PHP对XML文件操作类讲解
<?phpclass XML{ private $dom; function __construct () { $this->dom = new D ...
随机推荐
- 【SqlServer】Sqlserver中的DOS命令操作
输入osql ?查看是否支持当前版本,如果是SQL Server 2005以上用Sqlcmd , 以下用Osql连接数据库(a)Osql -S localhost -U username -P p ...
- 二值化函数cvThreshold()参数CV_THRESH_OTSU的疑惑【转】
查看OpenCV文档cvThreshold(),在二值化函数cvThreshold(const CvArr* src, CvArr* dst, double threshold, double max ...
- prestashop nginx rewrite rule
server { listen *:; server_name www.mydomain.com *.mydomain.com; root /var/www/www.mydomain.com/web; ...
- Git教程学习(四)
12. 分支管理场景 多人协同工作时,你在优化代码X,需要较长时间才能完成,未完成之前会影响整体代码的使用.于是写完的代码不能提交到版本库,提交就会影响别人使用整体的代码.不提交你就失去了git的版本 ...
- ASCII、Unicode和UTF-8编码的区别
归纳: 编码 大小 支持语言 ASCII 1个字节 英文 Unicode 2个字节(生僻字4个) 所有语言 UTF-8 1-6个字节,英文字母1个字节,汉字3个字节,生僻字4-6个字节 所有语言 具体 ...
- Spring Boot 2.0 入门指南
0x01 什么是Spring Boot? Spring Boot是用来简化Spring应用初始搭建以及开发过程的全新框架,被认为是Spring MVC的“接班人”,和微服务紧密联系在一起. 0x02 ...
- python thrift使用实例
前言 Apache Thrift 是 Facebook 实现的一种高效的.支持多种编程语言的远程服务调用的框架.本文将从 Python开发人员角度简单介绍 Apache Thrift 的架构.开发和使 ...
- 【转载】ssh-keygen 基本用法
[转载]ssh-keygen 基本用法 原文地址:https://www.liaohuqiu.net/cn/posts/ssh-keygen-abc/ ssh 公钥认证是ssh认证的方式之一.通过公钥 ...
- linux每日命令(11):cat命令
cat命令的用途是连接文件或标准输入并打印.这个命令常用来显示文件内容,或者将几个文件连接起来显示,或者从标准输入读取内容并显示,它常与重定向符号配合使用. 一.命令格式: cat [参数] [文件] ...
- Hack mind
试 卷 姓名________ 学号________ 首先我们来看这个,试卷的名字和编号填写,这个部分有“漏洞”吗?有 学生的姓名和编号都写在这儿,没有做任何保护措施,因此,你只要偷看了某人的试卷上的这 ...