C# LINQ XML to Dictionary Collection
using System; using System.Collections.Generic; using System.Linq; using System.Xml.Linq; public static Dictionary<string, object> GetAttribute(string xml){ XElement ele = XElement.Parse(xml); return (from e in ele.Elements() select new KeyValuePair<string, object>(e.Name.LocalName, e.Value)).ToDictionary(k => k.Key, v => v.Value); } |
<objectx> <news_id>xxxxx</news_id> <news_title>xxxxx</news_title> <news_desc>xxxxx</news_desc> <news_date>xxxxx</news_date> </objectx> |