📄 xmlcontrol.cs
字号:
#region Using directives
using System;
using System.Data;
using System.IO;
using System.Collections;
using System.Xml;
using System.Xml.Serialization;
using BTHWrapper;
#endregion
namespace ControlUtil
{
/// <summary>
/// Summary description for XMLControl.
/// </summary>
public class XMLControl
{
public static void WriteDeviceList(ArrayList lstDeviceItem, string strPath)
{
XmlDocument xmlDoc = new XmlDocument();
// Write down the XML declaration
XmlDeclaration xmlDeclaration = xmlDoc.CreateXmlDeclaration("1.0", "utf-8", null);
// Create the root element
XmlElement rootNode = xmlDoc.CreateElement("DeviceList");
xmlDoc.InsertBefore(xmlDeclaration, xmlDoc.DocumentElement);
xmlDoc.AppendChild(rootNode);
// Create a new <Category> element and add it to the root node
XmlElement parentNode;
IEnumerator ie = lstDeviceItem.GetEnumerator();
DeviceItem _deviceItem = new DeviceItem();
while (ie.MoveNext())
{
_deviceItem = (DeviceItem)ie.Current;
parentNode = xmlDoc.CreateElement("Device");
parentNode.SetAttribute("Name", _deviceItem.DeviceName);
parentNode.SetAttribute("Address", _deviceItem.Address);
xmlDoc.DocumentElement.AppendChild(parentNode);
}
xmlDoc.Save(strPath);
}
public static ArrayList ReadDeviceList(string strPath)
{
ArrayList lstDevice = new ArrayList();
XmlDocument doc = new XmlDocument();
doc.Load(strPath);
XmlNodeReader reader = new XmlNodeReader(doc);
while (reader.Read())
{
switch (reader.NodeType)
{
case XmlNodeType.Element:
if (reader.Name.Equals("Device"))
{
string strDevice = "";
string strAddr = "";
for (int i = 0; i < reader.AttributeCount; i++)
{
reader.MoveToAttribute(i);
if (reader.Name == "Name") strDevice = reader.Value;
if (reader.Name == "Address") strAddr = reader.Value;
}
lstDevice.Add(new DeviceItem(strDevice, strAddr));
}
break;
default:
break;
}
}
return lstDevice;
}
public static void WriteProfile()
{
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -