Reputation: 353
I have a Xml such as 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 a list such as below list:
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"}
Upvotes: 4
Views: 103
Reputation: 35126
var allAttributes = XDocument.Parse(xmlInString)
.Descendants()
.Where(e => e.HasAttributes)
.SelectMany(e => e.Attributes())
.ToList();
Upvotes: 2