Add elements to xml file in WP7?

后端 未结 2 1012
挽巷
挽巷 2021-01-25 03:15

How do you add an element to an xml file in wp7? I HAVE found alot of sources that show how to add elements in ASP.NET, Silverlight on the browser, etc.. but nothing on wp7. I k

2条回答
  •  执念已碎
    2021-01-25 03:28

    This is how I've been developing for WP7:

    using (var store = IsolatedStorageFile.GetUserStoreForApplication())
    {
        using (var fs = store.OpenFile("MyXmlFile.xml", FileMode.OpenOrCreate, FileAccess.ReadWrite))
        {
            var root = new XElement("Root");
            var someAttribute = new XAttribute("SomeAttribute", "Some Attribute Value");
            var child = new XElement("Child", "Child Value");
            var anotherChild = new XElement("AnotherChild", "Another Child Value");
            var xDoc = new XDocument();
            root.Add(someAttribute, child, anotherChild);
            xDoc.Add(root);
            xDoc.Save(fs);
        }
    }
    

提交回复
热议问题