1.读取xml文件
using System.Xml;
1-1:
XmlDocument xml = new XmlDocument();
xml.Load("XMLFile.xml");
string deviceIP = xml.SelectSingleNode("para/deviceIP").InnerText;
string devicePort = xml.SelectSingleNode("para/devicePort").InnerText;
string localIP = xml.SelectSingleNode("para/localIP").InnerText;
string localPort = xml.SelectSingleNode("para/localPort").InnerText;
1-2:
public class BDataStruct
{
public string mode;
ublic string ratioW;
public string ratioH;
public string[] filePath = new string[6];
public string[] delaytime = new string[6];
}<pre name="code" class="csharp"> if (File.Exists("ProgramConfig.xml"))
{
List<BDataStruct> m_PageDatas;
m_PageDatas = new List<BDataStruct>();
XmlDocument xml = new XmlDocument();
xml.Load("ProgramConfig.xml");
XmlElement rootElem = xml.DocumentElement; //获取根节点
XmlNodeList childNodes = rootElem.GetElementsByTagName("Para"); //获取Para子节点集合
//遍历读取xml的数据
foreach (XmlNode node in childNodes)
{
BDataStruct data = new BDataStruct();
data.mode = ((XmlElement)node).GetElementsByTagName("mode")[0].InnerText;
data.ratioW = ((XmlElement)node).GetElementsByTagName("ratioW")[0].InnerText;
data.ratioH = ((XmlElement)node).GetElementsByTagName("ratioH")[0].InnerText;
for (int j = 0; j < 6; j++)
{
string num = (j + 1).ToString();
data.filePath[j] = ((XmlElement)node).GetElementsByTagName("path" + num)[0].InnerText;
data.delaytime[j] = ((XmlElement)node).GetElementsByTagName("delay" + num)[0].InnerText;
}
m_PageDatas.Add(data);
}
}
{
public string mode;
ublic string ratioW;
public string ratioH;
public string[] filePath = new string[6];
public string[] delaytime = new string[6];
}<pre name="code" class="csharp"> if (File.Exists("ProgramConfig.xml"))
{
List<BDataStruct> m_PageDatas;
m_PageDatas = new List<BDataStruct>();
XmlDocument xml = new XmlDocument();
xml.Load("ProgramConfig.xml");
XmlElement rootElem = xml.DocumentElement; //获取根节点
XmlNodeList childNodes = rootElem.GetElementsByTagName("Para"); //获取Para子节点集合
//遍历读取xml的数据
foreach (XmlNode node in childNodes)
{
BDataStruct data = new BDataStruct();
data.mode = ((XmlElement)node).GetElementsByTagName("mode")[0].InnerText;
data.ratioW = ((XmlElement)node).GetElementsByTagName("ratioW")[0].InnerText;
data.ratioH = ((XmlElement)node).GetElementsByTagName("ratioH")[0].InnerText;
for (int j = 0; j < 6; j++)
{
string num = (j + 1).ToString();
data.filePath[j] = ((XmlElement)node).GetElementsByTagName("path" + num)[0].InnerText;
data.delaytime[j] = ((XmlElement)node).GetElementsByTagName("delay" + num)[0].InnerText;
}
m_PageDatas.Add(data);
}
}