XElement to Dictionary with same keys alternative

Irvilne

New Member
I have an xml like this\[code\]<parent id="001"> <first>Brian</first> <last>Johnson</last> <gender>Male</gender></parent>\[/code\]My code currently handles it as such:\[code\]public Dictionary<string, string> GetParentInfo(string id, XDocument xml){ var parent = xml.Descendants("parent") .Where(p => p.Attribute("id").Value =http://stackoverflow.com/questions/15796112/= id) .FirstOrDefault(); var parentInfo = parent.Elements() .ToDictionary(x => x.Name.LocalName, x => X.Value); return parentInfo;}\[/code\]My issue is that my xml is now changing to:\[code\]<parent id="001"> <first>Brian</first> <last>Johnson</last> <gender>Male</gender> <child>Jimmy</child> <child>Janet</child> <child>Carl</child></parent>\[/code\]Dictionary is no longer suitable and I can't think of how to handle this change.
 
Back
Top