【发布时间】:2015-12-06 14:19:26
【问题描述】:
我正在 Windows 商店中制作应用程序,但在创建的 xml 文件中写入 xml 时遇到问题。 我已关注此 Editing XML file in Windows Store App,但它对我不起作用。
我希望在单击按钮时将此 xml 写入我的 xml 文件中。
这些东西的任何替代方式..
<drink>
<drinkImage>ck.png</drinkImage>
<drinkTitle>COKE</drinkTitle>
<drinkDescription>(1793-1844)</drinkDescription>
</drink>
我当前的文件是这样的:
<?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>
这是我尝试过的:
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)
{
XDocument xmlDoc = XDocument.Load("favourite//fav.xml");
xmlDoc.Root.Add(new XElement("drink",
new XAttribute("drinkImage","ck.png"),
new XAttribute("drinkTitle","PEPSI"),
new XAttribute("drinkDescription","NONE")
));
xmlDoc.Save(xmlDoc); **//This isn't working in windows store ..**
}
}
}
}
【问题讨论】:
-
一定要用xml吗?以json格式存储数据有更方便的方式。
-
其实场景从这里开始..stackoverflow.com/questions/34094405/…
标签: c# xml windows-store-apps xmldocument