public static iPhoneApps ReadXmlStream(Stream inStream) { iPhoneApps appList = new iPhoneApps(); NodeCounts nodes = new NodeCounts(); XmlTextReader textReader = null; textReader = new XmlTextReader(inStream); textReader.Normalization = true; textReader.MoveToContent(); Boolean inDict = false; while (textReader.Read()) { XmlNodeType nType = textReader.NodeType; String type = nType.ToString(); String name = textReader.Name; String value = textReader.Value.ToString(); nodes.Inc(nType); switch (nType) { case XmlNodeType.Element: //Console.WriteLine(nType.ToString() + ": " + textReader.Name.ToString()); switch (name) { case "dict": if (!inDict) { appList.Add(); inDict = true; } break; case "key": appList.Last = PListNodeType.PLKey; break; case "string": appList.Last = PListNodeType.PLString; break; } break; case XmlNodeType.Text: //Console.WriteLine(nType.ToString() + ": " + textReader.Value.ToString()); switch (appList.Last) { case PListNodeType.PLKey: appList.Key = value; break; case PListNodeType.PLString: appList.Value = value; appList.ApplyKey(); break; } break; case XmlNodeType.EndElement: switch (name) { case "dict": inDict = false; break; case "key": //appList.ApplyKey(); break; } break; case XmlNodeType.Whitespace: break; default: //Console.WriteLine(nType.ToString() + ": " + textReader.Name.ToString()); break; } } for (Int32 i = 0; i < nodes.Count; i++ ) { NodeCount node = nodes.Nodes[i]; Console.WriteLine(node.ToString() + ": " + node.Count.ToString()); } return appList; }
public static iPhoneApps ReadXmlStream(Stream inStream) { iPhoneApps appList = new iPhoneApps(); NodeCounts nodes = new NodeCounts(); XmlTextReader textReader = null; textReader = new XmlTextReader(inStream); textReader.Normalization = true; textReader.MoveToContent(); Boolean inDict = false; while (textReader.Read()) { XmlNodeType nType = textReader.NodeType; String type = nType.ToString(); String name = textReader.Name; String value = textReader.Value.ToString(); nodes.Inc(nType); switch (nType) { case XmlNodeType.Element: //Console.WriteLine(nType.ToString() + ": " + textReader.Name.ToString()); switch (name) { case "dict": if (!inDict) { appList.Add(); inDict = true; } break; case "key": appList.Last = PListNodeType.PLKey; break; case "string": appList.Last = PListNodeType.PLString; break; } break; case XmlNodeType.Text: //Console.WriteLine(nType.ToString() + ": " + textReader.Value.ToString()); switch (appList.Last) { case PListNodeType.PLKey: appList.Key = value; break; case PListNodeType.PLString: appList.Value = value; appList.ApplyKey(); break; } break; case XmlNodeType.EndElement: switch (name) { case "dict": inDict = false; break; case "key": //appList.ApplyKey(); break; } break; case XmlNodeType.Whitespace: break; default: //Console.WriteLine(nType.ToString() + ": " + textReader.Name.ToString()); break; } } for (Int32 i = 0; i < nodes.Count; i++) { NodeCount node = nodes.Nodes[i]; Console.WriteLine(node.ToString() + ": " + node.Count.ToString()); } return(appList); }