LINQ TO XML练习
生活随笔
收集整理的這篇文章主要介紹了
LINQ TO XML练习
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
最近要用到LINQ,以前沒用到過,進入linq的學習中............
下面是我朋友給的練習
using System;using System.Collections.Generic;
using System.Linq;
using System.Xml.Linq;
using System.Text;
namespace ConsoleApplication3
{
class Program
{
static void Main(string[] args)
{
Dictionary<string, string> xDic = new Dictionary<string, string>();
XDocument xDoc = XDocument.Load("D:\\Example.xml");
XElement xEle = xDoc.Root;
IEnumerable<XElement> xEnum = xEle.Elements();
foreach (XElement xEleJSCommand in xEnum)
{
string strKey = "JS:";
strKey += xEleJSCommand.Attribute("xmlns").Value.ToString()+".";
IEnumerable<XElement> xEleCom = xEleJSCommand.Elements();
foreach (XElement xEleCommand in xEleCom)
{
strKey += xEleCommand.Attribute("name").Value.ToString();
xDic.Add(strKey, xEleCommand.Value.ToString());
}
}
foreach(KeyValuePair<string,string> kevp in xDic)
{
Console.WriteLine("Key:{0}\nvalue:{1}", kevp.Key, kevp.Value);
}
Console.ReadKey();
}
}
}
總結
以上是生活随笔為你收集整理的LINQ TO XML练习的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 海伦钢琴股票怎么样 这两天大涨了一波
- 下一篇: vtho是什么币