XML操作

读取一个网络XML: http://www.proxycn.com/proxylist.xml
由于直接保存出来的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 {
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}

你可能感兴趣的:(xml)