I have a plist in this format:
<plist version="1.0">
<array>
<dict>
<key>Title</key>
<string>Chapters</string>
<key>Items</key>
<array>
<dict>
<key>Title</key>
<string>XYZ</string>
</dict>
<dict>
<key>Title</key>
<string>ABC</string>
</dict>
</array>
</dict>
<dict>
<key>Title</key>
<string>ChaptersONE</string>
<key>Items</key>
<array>
<dict>
<key>Title</key>
<string>ASDF</string>
</dict>
</array>
</dict>
</array>
I have a Class Chapters class with String and List :
i need it like this:
Chapters contains list of subtopics like XYZ and ABC and so on...
ChaptersONE contains list of subtopics like ASDF and so on...
Now i have tried it like this:
XDocument doc = XDocument.Load(FileName);// plist file name
XElement plist = doc.Element("plist");
XElement array = plist.Element("array");
Chapters chapters = null;
String keyValue = String.Empty;
chapters.listOfItems = new List<Chapters>();
using (XmlReader reader = array.CreateReader())
{
reader.MoveToContent();
while (reader.Read())
{
if (reader.NodeType == XmlNodeType.Element)
{
if (reader.Name == "dict")
{
chapters = new Chapters();
listOfItems.Add(chapters);
}
else if (reader.Name == "key")
{
if (!reader.Read())
{
break;
}
else if (reader.NodeType == XmlNodeType.Text || reader.NodeType == XmlNodeType.CDATA)
{
keyValue = reader.Value;
}
}
else if (reader.Name == "string")
{
if (!reader.Read())
{
break;
}
else if (highwayCode != null && reader.NodeType == XmlNodeType.Text || reader.NodeType == XmlNodeType.CDATA)
{
switch (keyValue)
{
case "Title":
chapters.Header = reader.Value;
break;
case "Items":
break;
default:
break;
}
}
}
}
}
}
But i all the Main title (Headers like Chapters and ChaptersOne) and also the subtopics are just assigning to only the string, what am i doing wrong here ?
How to fix acheive this ?
EDIT
Chapters should contains list of subtopics like XYZ and ABC and so on...
ChaptersONE should contains list of subtopics like ASDF and so on...
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…