79 lines
2.0 KiB
C#
79 lines
2.0 KiB
C#
|
|
using System;
|
|||
|
|
using System.Collections.Generic;
|
|||
|
|
using System.Linq;
|
|||
|
|
using System.Data;
|
|||
|
|
using System.Text;
|
|||
|
|
using System.Xml;
|
|||
|
|
using System.Xml.Linq;
|
|||
|
|
|
|||
|
|
namespace WMS.Common
|
|||
|
|
{
|
|||
|
|
public class XMLHelper
|
|||
|
|
{
|
|||
|
|
#region 构造函数
|
|||
|
|
/// <summary>
|
|||
|
|
/// 构造函数
|
|||
|
|
/// </summary>
|
|||
|
|
public XMLHelper() { }
|
|||
|
|
#endregion
|
|||
|
|
|
|||
|
|
private XDeclaration Declaration = new XDeclaration("1.0", "uft-8", "no");
|
|||
|
|
|
|||
|
|
|
|||
|
|
#region 创建XML
|
|||
|
|
/// <summary>
|
|||
|
|
/// 根据XElement创建XML文件
|
|||
|
|
/// </summary>
|
|||
|
|
/// <param name="el"></param>
|
|||
|
|
/// <param name="filename"></param>
|
|||
|
|
public static void CreateXML(XElement el, string filename)
|
|||
|
|
{
|
|||
|
|
XDocument doc = new XDocument(el);
|
|||
|
|
doc.Save(filename);
|
|||
|
|
}
|
|||
|
|
/// <summary>
|
|||
|
|
/// 根据XML文本文件内容创建XML
|
|||
|
|
/// </summary>
|
|||
|
|
/// <param name="xml"></param>
|
|||
|
|
/// <param name="filename"></param>
|
|||
|
|
public void CreateXML(string xml, string filename)
|
|||
|
|
{
|
|||
|
|
XElement el = XElement.Parse(xml);
|
|||
|
|
XDocument doc = new XDocument(Declaration, el);
|
|||
|
|
doc.Save(filename, SaveOptions.None);
|
|||
|
|
}
|
|||
|
|
/// <summary>
|
|||
|
|
/// 将DataTable转化成XML文件,并保存
|
|||
|
|
/// </summary>
|
|||
|
|
/// <param name="table"></param>
|
|||
|
|
/// <param name="fileName"></param>
|
|||
|
|
public void CreateXML(DataTable table, string fileName)
|
|||
|
|
{
|
|||
|
|
//设置默认xml文件名
|
|||
|
|
if (string.IsNullOrEmpty(fileName))
|
|||
|
|
{
|
|||
|
|
fileName = @"XMLData\" + table.TableName;
|
|||
|
|
}
|
|||
|
|
DataSet ds = new DataSet();
|
|||
|
|
ds.Tables.Add(table);
|
|||
|
|
ds.WriteXml(fileName);
|
|||
|
|
}
|
|||
|
|
#endregion
|
|||
|
|
|
|||
|
|
#region 查询XML文件
|
|||
|
|
public void SelectXML(string fileName, string Node)
|
|||
|
|
{
|
|||
|
|
|
|||
|
|
}
|
|||
|
|
#endregion
|
|||
|
|
|
|||
|
|
#region UpdateXML
|
|||
|
|
|
|||
|
|
#endregion
|
|||
|
|
|
|||
|
|
#region AddXml
|
|||
|
|
|
|||
|
|
#endregion
|
|||
|
|
}
|
|||
|
|
}
|