C#读取XML文件

FtpInfo类

 1   #region Ftp信息类
 2     /// <summary>
 3     /// Ftp信息类
 4     /// </summary>
 5     public class FtpInfo
 6     {
 7         private string sFtpUriD;
 8         private string sFilePathD;
 9         private string sFtpUserD;
10         private string sFtpPwdD;
11         private string sFtpUriU;
12         private string sFilePathU;
13         private string sFtpUserU;
14         private string sFtpPwdU;
15 
16         /// <summary>
17         /// 源ftp url:ftp://ip+port
18         /// </summary>
19         public string SFtpUriD
20         {
21             get { return sFtpUriD; }
22             set { sFtpUriD = value; }
23         }
24         /// <summary>
25         /// 源ftp 文件路径:/xxx/xxx/xxx
26         /// </summary>
27         public string SFilePathD
28         {
29             get { return sFilePathD; }
30             set { sFilePathD = value; }
31         }
32         /// <summary>
33         /// 源ftp用户名
34         /// </summary>
35         public string SFtpUserD
36         {
37             get { return sFtpUserD; }
38             set { sFtpUserD = value; }
39         }
40         /// <summary>
41         /// 源ftp密码
42         /// </summary>
43         public string SFtpPwdD
44         {
45             get { return sFtpPwdD; }
46             set { sFtpPwdD = value; }
47         }
48         /// <summary>
49         /// 目的ftp url:ftp://ip+port
50         /// </summary>
51         public string SFtpUriU
52         {
53             get { return sFtpUriU; }
54             set { sFtpUriU = value; }
55         }
56         /// <summary>
57         /// 目的ftp 文件路径:/xxx/xxx/xxx
58         /// </summary>
59         public string SFilePathU
60         {
61             get { return sFilePathU; }
62             set { sFilePathU = value; }
63         }
64         /// <summary>
65         /// 目的ftp用户名
66         /// </summary>
67         public string SFtpUserU
68         {
69             get { return sFtpUserU; }
70             set { sFtpUserU = value; }
71         }
72         /// <summary>
73         /// 目的ftp密码
74         /// </summary>
75         public string SFtpPwdU
76         {
77             get { return sFtpPwdU; }
78             set { sFtpPwdU = value; }
79         }
80     }
81     #endregion

FtpInfoXML文件

 1  1 <?xml version="1.0" encoding="utf-8" ?>
 2  2 <FtpList>
 3  3   <FtpInfo>
 4  4     <sFtpUriD>ftp://*.*.*.*:2122/</sFtpUriD>
 5  5     <sFilePathD>/</sFilePathD>
 6  6     <sFtpUserD>user</sFtpUserD>
 7  7     <sFtpPwdD>pwd</sFtpPwdD>
 8  8     <sFtpUriU>ftp://*.*.*.*:2121/</sFtpUriU>
 9  9     <sFilePathU>/</sFilePathU>
10 10     <sFtpUserU>sanpi1992@outlook.com</sFtpUserU>
11 11     <sFtpPwdU>YunChao*#</sFtpPwdU>
12 12   </FtpInfo>
13 13   <FtpInfo>
14 14     <sFtpUriD>ftp://*.*.*.*:2122/</sFtpUriD>
15 15     <sFilePathD>/</sFilePathD>
16 16     <sFtpUserD>user</sFtpUserD>
17 17     <sFtpPwdD>pwd</sFtpPwdD>
18 18     <sFtpUriU>ftp://*.*.*.*:2124/</sFtpUriU>
19 19     <sFilePathU>/</sFilePathU>
20 20     <sFtpUserU>sanpi1992@outlook.com</sFtpUserU>
21 21     <sFtpPwdU>YunChao*#</sFtpPwdU>
22 22   </FtpInfo>
23 23   <FtpInfo>
24 24     <sFtpUriD>ftp://*.*.*.*:2122/</sFtpUriD>
25 25     <sFilePathD>/</sFilePathD>
26 26     <sFtpUserD>user</sFtpUserD>
27 27     <sFtpPwdD>pwd</sFtpPwdD>
28 28     <sFtpUriU>ftp://*.*.*.*:2122/</sFtpUriU>
29 29     <sFilePathU>/</sFilePathU>
30 30     <sFtpUserU>user</sFtpUserU>
31 31     <sFtpPwdU>pwd</sFtpPwdU>
32 32   </FtpInfo>
33 33 </FtpList>

 

读取函数

 1 /// <summary>
 2         /// 获取FTPList
 3         /// </summary>
 4         /// <returns></returns>
 5         public static List<FtpInfo> GetFtpInfoList()
 6         {
 7             List<FtpInfo> FtpInfoList = new List<FtpInfo>();
 8             XmlDocument doc = new XmlDocument();
 9             doc.Load(ConfigurationManager.AppSettings["ftpFileInfoXMLPath"]);
10             XmlNode xn = doc.SelectSingleNode("FtpList");
11             XmlNodeList xnl = xn.ChildNodes;
12             foreach (XmlNode xn1 in xnl)
13             {
14                 XmlElement xe = (XmlElement)xn1;
15                 XmlNodeList xnl0 = xe.ChildNodes;
16                 FtpInfo ftpInfo = new FtpInfo();
17                 ftpInfo.SFtpUriD = xnl0.Item(0).InnerText;
18                 ftpInfo.SFilePathD = xnl0.Item(1).InnerText;
19                 ftpInfo.SFtpUserD = xnl0.Item(2).InnerText;
20                 ftpInfo.SFtpPwdD = xnl0.Item(3).InnerText;
21                 ftpInfo.SFtpUriU = xnl0.Item(4).InnerText;
22                 ftpInfo.SFilePathU = xnl0.Item(5).InnerText;
23                 ftpInfo.SFtpUserU = xnl0.Item(6).InnerText;
24                 ftpInfo.SFtpPwdU = xnl0.Item(7).InnerText;
25                 FtpInfoList.Add(ftpInfo);
26             }
27             return FtpInfoList;
28         }

 

posted @ 2017-07-12 09:38  sanpi1992  阅读(285)  评论(0编辑  收藏  举报