Get attributes Name and Value of element in C# through System.Linq

CyberVenomX

New Member
I have one custom config file.\[code\]<Students> <student> <Detail Name="abc" Class="1st Year"> <add key="Main" value="http://stackoverflow.com/questions/10733342/web"/> <add key="Optional" value="http://stackoverflow.com/questions/10733342/database"/> </Detail> </student></Students>\[/code\]I read this file through the IConfigurationHandler interface implementation. When I read the childNode attributes of Detail element. It return me below result into Immediate Window of IDE.\[code\]elem.Attributes.ToObjectArray(){object[2]} [0]: {Attribute, Name="key", Value="http://stackoverflow.com/questions/10733342/Main"} [1]: {Attribute, Name="value", Value="http://stackoverflow.com/questions/10733342/web"}\[/code\]When I try to write on Console\[code\] Console.WriteLine("Value '{0}'",elem.Attributes.ToObjectArray());\[/code\]it's return me \[code\]Value : 'System.Configuration.ConfigXmlAttribute'\[/code\]\[code\]elem.Attributes.Item(1)\[/code\] method give me the Name and Value detail but here I need to pass the index value of attribute which I don't know currently.I want to get Name and value of attribute through LINQ query and individual display on Console for each childNode attribute.\[code\]Value : Name="Key" and Value="http://stackoverflow.com/questions/10733342/Main" Name="value", Value="http://stackoverflow.com/questions/10733342/web"\[/code\]
 
Back
Top