I am making an app in windows store and having a problem in writing xml in created xml file. I have followed this Editing XML file in Windows Store App but it didn't work for me.
I want this xml to be wrote in my xml file on button click.
<drink> <drinkImage>ck.png</drinkImage> <drinkTitle>COKE</drinkTitle> <drinkDescription>(1793-1844)</drinkDescription> </drink> my current file is this:
<?xml version="1.0" encoding="utf-8" ?> <drinks> <drink> <drinkImage>pepsi.png</drinkImage> <drinkTitle>PEPSI</drinkTitle> <drinkDescription>(1793-1844)</drinkDescription> </drink> **<here I Want above xml on button click>** </drinks> Here is what I have tried:
namespace DrinksApp { /// <summary> /// An empty page that can be used on its own or navigated to within a Frame. /// </summary> public sealed partial class coke : Page { public coke() { this.InitializeComponent(); } XmlDocument dom = new XmlDocument(); private void Button_Click(object sender, RoutedEventArgs e) { this.Frame.Navigate(typeof(softdrinks)); } private async void Button_Click_1(object sender, RoutedEventArgs e) { StorageFolder sf = await ApplicationData.Current.LocalFolder.CreateFolderAsync("favourite", CreationCollisionOption.OpenIfExists); StorageFile st = await sf.CreateFileAsync("fav.xml", CreationCollisionOption.OpenIfExists); var content = await FileIO.ReadTextAsync(st); if (!string.IsNullOrEmpty(content)) { dom.LoadXml(content); var existingRoot = dom.SelectSingleNode("//drink"); var childTag = dom.CreateElement("drink"); childTag.InnerText = "ck.png"; existingRoot.AppendChild(childTag); var childertag = dom.CreateElement("drinkImage"); childertag.InnerText = "COKE"; childTag.AppendChild(childertag); var childertag2 = dom.CreateElement("drinkTitle"); childertag2.InnerText = "Nothing"; childTag.AppendChild(childertag2); var childertag3 = dom.CreateElement("drinkDescription"); childTag.AppendChild(childertag3); await dom.SaveToFileAsync(st); } } } }

No comments:
Post a Comment