📄 xmlmanager.cs
字号:
using System;
using System.Collections.Generic;
using System.Text;
using System.Data;
using System.Xml;
using System.Windows.Forms;
using System.Collections;
using System.Drawing;
using System.IO;
namespace LC_DataIO
{
public class XmlManager
{
private string path = "";
public string[] ds;
private ArrayList al = new ArrayList();
public struct objbtn
{
public string objname;
public Point pos;
}
public XmlManager(string path)
{
this.path = path;
}
public void setAttribteValue(string key,string parent, string attribteName, string value)
{
XmlDocument xmlDoc = new XmlDocument();
xmlDoc.Load(this.path);
XmlNodeList xnl = xmlDoc.SelectSingleNode(parent).ChildNodes;
foreach (XmlNode xn in xnl)
{
XmlElement xe = (XmlElement)xn;
if (xe.ChildNodes[0].Value == key)
{
xe.SetAttribute(attribteName, value);
break;
}
}
xmlDoc.Save(this.path);
}
public string getAttribteValue(string key,string attribteName)
{
System.Xml.XmlTextReader xtr = new XmlTextReader(this.path);
try
{
while (xtr.Read())
{
if (xtr.NodeType != XmlNodeType.EndElement && xtr.NodeType != XmlNodeType.Whitespace && !xtr.IsStartElement("Converter") && !xtr.IsStartElement("xml"))
{
if (xtr.NodeType == XmlNodeType.Element)
{
xtr.MoveToAttribute(attribteName);
string temp = xtr.Value.ToString();
xtr.Read();
string text = xtr.Value.ToString().Replace("/r/n", "");
if (text.Trim() == key)
{
return temp;
}
}
}
}
}
catch (Exception e)
{
MessageBox.Show(e.ToString());
}
finally
{
xtr.Close();
}
return "";
}
public static void SourceToXml(DataTable dt,Hashtable allfileds)
{
}
public static void XmlToDes()
{
}
public static ArrayList getRows()
{
ArrayList al = new ArrayList();
string temp = "";
System.Xml.XmlTextReader xtr = new XmlTextReader(Application.StartupPath+"//data//temp.xml");
try
{
while (xtr.Read())
{
if (xtr.NodeType != XmlNodeType.EndElement && xtr.NodeType != XmlNodeType.Whitespace && !xtr.IsStartElement("ROOT") && !xtr.IsStartElement("xml"))
{
if (xtr.IsStartElement("Rows"))
{
if (temp != "")
al.Add(temp);
temp = "";
}
else
{
string nodename = xtr.Name;
xtr.MoveToAttribute("type");
temp += "type=" + xtr.Value.ToString() + "■";
xtr.Read();
temp += nodename + "=" + xtr.Value.ToString() + "|";
}
}
}
}
catch (Exception e)
{
MessageBox.Show(e.ToString());
}
finally
{
xtr.Close();
}
return al;
}
public ArrayList getAllObj()
{
al.Clear();
System.Xml.XmlTextReader xtr = new XmlTextReader(this.path);
try
{
while (xtr.Read())
{
objbtn ob = new objbtn();
if (xtr.NodeType == XmlNodeType.EndElement && xtr.Name == "xml")
break;
else
{
if (xtr.NodeType != XmlNodeType.EndElement && xtr.NodeType != XmlNodeType.Whitespace && !xtr.IsStartElement("Converter"))
{
if (xtr.NodeType == XmlNodeType.Element)
{
xtr.MoveToAttribute("posx");
ob.pos.X = Convert.ToInt32(xtr.Value.ToString());
xtr.MoveToAttribute("posy");
ob.pos.Y = Convert.ToInt32(xtr.Value.ToString());
xtr.Read();
ob.objname = xtr.Value.ToString().Replace("/r/n", "");
al.Add(ob);
}
}
}
}
//MessageBox.Show(xtr..ToString());
}
catch (Exception e)
{
MessageBox.Show(e.ToString());
}
finally
{
xtr.Close();
}
return al;
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -