zoukankan      html  css  js  c++  java
  • 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();
    }
    }
    }
  • 相关阅读:
    vim tab 和4个空格
    python 入门
    pyenv 以及 virtualenv
    Redis Cluster 理论知识
    使用Redis SETNX 命令实现分布式锁
    go runtime scheduler
    LeetCode Valid Parentheses
    LeetCode Rotate Image
    leetcode
    HDU 3657 Game(取数 最小割)经典
  • 原文地址:https://www.cnblogs.com/JuneZhang/p/1964906.html
Copyright © 2011-2022 走看看