<...">

Getting Xml Attributes

I have an Xml like below:

<Phrase Entry="ID"> <Ans number="1"> <Identification LastName="Bornery" Name="John" Age="23"/> <Identification LastName="Grify" Name="Johnson" Age="29"/> <Identification LastName="Alisen" Name="Julia" Age="38" City="NewYork" Job="Teacher"/> <Identification LastName="Bornery" Name="John" Weight="85"/> </Ans> </Phrase> 

and I want to list the Xml attributes with their values ​​in the list, for example below:

 MyList = {LastName="Bornery" , Name="John", Age="23" , LastName="Grify" , Name="Johnson", Age="29", LastName="Alisen", Name="Julia", Age="38", City="NewYork", Job="Teacher", LastName="Bornery", Name="John", Weight="85"} 
+4
source share
1 answer
 var allAttributes = XDocument.Parse(xmlInString) .Descendants() .Where(e => e.HasAttributes) .SelectMany(e => e.Attributes()) .ToList(); 
+2
source

All Articles