c# - Converting an xml into list of anonymous object -


After

I have a xml which includes language details like

  & lt; LanguageList & gt; ; & Lt; Language code = "EN-US" name = "English - United States" & gt; & Lt; / Language & gt; & Lt; Language Code = "N-UK" name = "English - United Kingdom" & gt; & Lt; / Language & gt; - - & lt; / Language list & gt;  

I want to convert this to a list of anonymous objects where each object has two field codes and names.

I have the following linq expression

  var anonList = (from the xDoc.Descendants ("language list"). DescendantNodes () Choose U.Olist (); Like  

this

is giving all the nodes under LanguageList
  & lt; Language code = "EN-US" name = "English - United Sates" & gt; & Lt; / Language & gt; & Lt; Language Code = "N-UK" name = "English - United Kingdom" & gt; & Lt; / Language & gt;  

I tried to add something where the clauses and other methods .. but they are not able to get it.

You need to get the attribute of making each node more anonymous object like this:

  listOfLanguages ​​= xDoc.Descendants ( "LanguageList") Scion () .Select (L = & gt; new {name = l.Attribute ("name") value .., code = L. attribute ("code"). Value});  

Comments

Popular posts from this blog

winforms - C# Form - Property Change -

java - Messages from .properties file do not display UTF-8 characters -

javascript - amcharts makechart not working -