I am working on Windows Phone 8 application,
I have some UI which looks like this :
Main Item A --- has its desc and list of subitems as key value
Main Item B --- has its desc and list of subitems as key value
Main Item C --- has its desc and list of subitems as key value
Now on click of A move to next page which will display its Description and its sub items.
On click of Main Item A
Description of Main Item A
sub item 1 --- On click of this display its desc sub item 2 --- On click of this display its desc
Here is how Xml looks like:
<plist version="1.0">
<dict>
<key>Category</key>
<array>
<dict>
<key>Name</key>
<string>A</string>
<key>Description</key>
<string>Some data</string>
<key>SubItems</key>
<array>
<dict>
<key>Description</key>
<string>Some data</string>
<key>Name</key>
<string>One</string>
</dict>
<dict>
<key>Name</key>
<string>Two</string>
<key>Description</key>
<string>Some data</string>
</dict>
</array>
</dict>
<dict>
<key>Name</key>
<string>B</string>
<key>Description</key>
<string>Some data</string>
<key>SubItems</key>
<array>
<dict>
<key>Description</key>
<string>Some data</string>
<key>Name</key>
<string>One</string>
</dict>
<dict>
<key>Name</key>
<string>Two</string>
<key>Description</key>
<string>Some data</string>
</dict>
</array>
</dict>
How to parse this example ?
UPDATE
I have solved like this :
Dictionary<string, List<Tricks>> plistData =
doc.Root.Element("dict").Element("array").Elements("dict")
.Select(GetValues)
.ToDictionary(v => (string)v["Name"],
v => v["SubItems"]
.Elements("dict").Select(Parse).ToList());
static Tricks Parse(XElement dict)
{
var values = GetValues(dict);
return new Tricks
{
SubTitle = (string)values["Name"],
SubTitleDescription = (string)values["Description"]
};
}
static Dictionary<string, XElement> GetValues(XElement dict)
{
return dict.Elements("key")
.ToDictionary(k => (string)k, k => (XElement)k.NextNode);
}
In the above i am able to get everything but except MainTitle Description
, can you please help me to correct it.