XML操作
读取一个网络XML: http://www.proxycn.com/proxylist.xml
由于直接保存出来的XML文件会出现错误,因此直接在代码中引用Xml文件的URI
用XmlDocument实现
由于直接保存出来的XML文件会出现错误,因此直接在代码中引用Xml文件的URI
用XmlDocument实现
1
using System;
2
using System.Collections.Generic;
3
using System.ComponentModel;
4
using System.Data;
5
using System.Drawing;
6
using System.Text;
7
using System.Windows.Forms;
8
using System.Xml;
9
using System.IO;
10
11
namespace WindowsApplication1
12
{
13
public partial class Form1 : Form
14
{
15
public Form1()
16
{
17
InitializeComponent();
18
}
19
20
private void button1_Click(object sender, EventArgs e)
21
{
22
XmlDocument XmlDoc = new XmlDocument();
23
XmlDoc.Load("http://www.proxycn.com/proxylist.xml");
24
//XPath:结点全路径(m2proxy/proxylist/proxy)+结点标记([@type=0])
25
XmlNodeList XNL = XmlDoc.SelectNodes("m2proxy/proxylist/proxy[@type=0]");
26
27
for (int i = 0; i < XNL.Count; i++)
28
{
29
XmlNode XN = XNL.Item(i);
30
MessageBox.Show(XN.Attributes["address"].Value);//用MessageBox纯为展示
31
}
32
}
33
}
34
}

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

22

23

24

25

26

27

28

29

30

31

32

33

34
