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