private static void CheckDocument(PListDocument document) { Assert.IsNotNull(document.Root); Assert.IsNotNull(document.Root.Dict); Assert.IsTrue(document.Root.Dict.ContainsKey("CFBundleDevelopmentRegion")); Assert.IsTrue(document.Root.Dict.ContainsKey("CFBundleExecutable")); Assert.IsTrue(document.Root.Dict.ContainsKey("CFBundleIconFile")); Assert.IsTrue(document.Root.Dict.ContainsKey("CFBundleIdentifier")); Assert.IsTrue(document.Root.Dict.ContainsKey("CFBundleInfoDictionaryVersion")); Assert.IsTrue(document.Root.Dict.ContainsKey("CFBundleName")); Assert.IsTrue(document.Root.Dict.ContainsKey("CFBundlePackageType")); Assert.IsTrue(document.Root.Dict.ContainsKey("CFBundleSignature")); Assert.IsTrue(document.Root.Dict.ContainsKey("CFBundleShortVersionString")); Assert.IsTrue(document.Root.Dict.ContainsKey("LSMinimumSystemVersion")); Assert.IsTrue(document.Root.Dict.ContainsKey("CFBundleVersion")); Assert.AreEqual("1", (String) (PListString) document.Root.Dict["CFBundleVersion"]); Assert.IsTrue(document.Root.Dict.ContainsKey("NSMainNibFile")); Assert.AreEqual("MainMenu", (String) (PListString) document.Root.Dict["NSMainNibFile"]); Assert.IsTrue(document.Root.Dict.ContainsKey("NSPrincipalClass")); Assert.AreEqual("NSApplication", (String) (PListString) document.Root.Dict["NSPrincipalClass"]); }
/// <summary> /// Loads a <see cref = "PListDocument" /> from a Xml content. /// </summary> /// <param name = "reader">The reader.</param> /// <returns>An instance of <see cref = "PListDocument" /></returns> public static PListDocument LoadFromXml(XmlReader reader) { PListDocument document = new PListDocument(true); // The XML parsing is based on a top-down stack exploration StringBuilder tempContent = new StringBuilder(); Stack <PListItemBase> stack = new Stack <PListItemBase>(); while (reader.Read()) { switch (reader.NodeType) { case XmlNodeType.Element: { String name = reader.Name; bool empty = reader.IsEmptyElement; // Collect all the attributes Dictionary <String, String> attributes = new Dictionary <String, String>(); if (reader.HasAttributes) { for (int i = 0; i < reader.AttributeCount; i++) { reader.MoveToAttribute(i); attributes.Add(reader.Name, reader.Value); } } // Create an object corresponding to the node PListItemBase item = Create(name); if (String.Equals("plist", name)) { // The "plist" node has a special treatment document.Root = item as PList; } else { // Append the node to the current parent node PListItemBase current = stack.Peek(); current.AppendChild(item); } // Push the new node in the context stack stack.Push(item); // Prepare the content collector for node with text tempContent = new StringBuilder(); // An empty node is pop right-away from the context stack if (empty) { stack.Pop(); item.SetValue(tempContent.ToString()); } } break; case XmlNodeType.EndElement: { // When the node ends, it is pop from the context stack and its content is set PListItemBase item = stack.Pop(); item.SetValue(tempContent.ToString()); } break; case XmlNodeType.Text: case XmlNodeType.CDATA: case XmlNodeType.SignificantWhitespace: { // Collect text content between start and end of the node String value = reader.Value; tempContent.Append(value); } break; } } return(document); }
/// <summary> /// Loads a <see cref = "PListDocument" /> from a Xml content. /// </summary> /// <param name = "reader">The reader.</param> /// <returns>An instance of <see cref = "PListDocument" /></returns> public static PListDocument LoadFromXml(XmlReader reader) { PListDocument document = new PListDocument(true); // The XML parsing is based on a top-down stack exploration StringBuilder tempContent = new StringBuilder(); Stack<PListItemBase> stack = new Stack<PListItemBase>(); while (reader.Read()) { switch (reader.NodeType) { case XmlNodeType.Element: { String name = reader.Name; bool empty = reader.IsEmptyElement; // Collect all the attributes Dictionary<String, String> attributes = new Dictionary<String, String>(); if (reader.HasAttributes) { for (int i = 0; i < reader.AttributeCount; i++) { reader.MoveToAttribute(i); attributes.Add(reader.Name, reader.Value); } } // Create an object corresponding to the node PListItemBase item = Create(name); if (String.Equals("plist", name)) { // The "plist" node has a special treatment document.Root = item as PList; } else { // Append the node to the current parent node PListItemBase current = stack.Peek(); current.AppendChild(item); } // Push the new node in the context stack stack.Push(item); // Prepare the content collector for node with text tempContent = new StringBuilder(); // An empty node is pop right-away from the context stack if (empty) { stack.Pop(); item.SetValue(tempContent.ToString()); } } break; case XmlNodeType.EndElement: { // When the node ends, it is pop from the context stack and its content is set PListItemBase item = stack.Pop(); item.SetValue(tempContent.ToString()); } break; case XmlNodeType.Text: case XmlNodeType.CDATA: case XmlNodeType.SignificantWhitespace: { // Collect text content between start and end of the node String value = reader.Value; tempContent.Append(value); } break; } } return document; }
public void WriteInfoPList(PListDocument document) { String path = Path.Combine(this.ContentsDirectory, "Info.plist"); document.WriteToFile(path); }