• 博客园logo
  • 会员
  • 众包
  • 新闻
  • 博问
  • 闪存
  • 赞助商
  • HarmonyOS
  • Chat2DB
    • 搜索
      所有博客
    • 搜索
      当前博客
  • 写随笔 我的博客 短消息 简洁模式
    用户头像
    我的博客 我的园子 账号设置 会员中心 简洁模式 ... 退出登录
    注册 登录
June's New World
知识和经验都是一点点积累的!现在努力也不晚,June加油!
博客园    首页    新随笔    联系   管理    订阅  订阅
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();
}
}
}
posted on 2011-02-25 15:09  冬雨在路上  阅读(472)  评论(0)    收藏  举报
刷新页面返回顶部
博客园  ©  2004-2025
浙公网安备 33010602011771号 浙ICP备2021040463号-3