http://www.w3school.com.cn/xml/xml_elements.asp
<?xml version="1.0" encoding="gb2312"?>
<string xmlns="http://tempuri.org/">200,2014/5/6 0:06:05</string>
获取如上XML中的200,2014/5/6 0:06:05
<?xml version="1.0" encoding="gb2312"?> <string xmlns="http://tempuri.org/">200,2014/5/6 0:06:05</string>
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Data.Entity.Validation; using System.Data.Entity; using System.Data.Objects; using System.Web; using System.Xml; namespace Test { class Program { static void Main(string[] args) { XmlDocument xml = new XmlDocument(); xml.Load("../../1.xml");//XML文件加载进来,路径看放的位置了,这里用了相对路径,绝对路径要好一些的 XmlNode node = xml.LastChild; foreach (XmlNode item in node.ChildNodes) { Console.WriteLine(item.InnerXml); Console.WriteLine(item.InnerText); //string v = item.Value;//节点的值 //string v1 = item.Attributes["xmlns"].Value;//节点属性值,这个获取会报错的,节点数据不对,需要其他全一些的XML数据 //string v2 = item["string"].Value;//元素值 //string v3 = item["string"].Attributes["xmlns"].Value;//元素属性值 //Console.WriteLine(v); //Console.WriteLine(v1); //Console.WriteLine(v2); //Console.WriteLine(v3); } Console.ReadKey(); } }
原文:http://www.cnblogs.com/danlis/p/5213090.html