当我单击保存按钮时,数据未保存在xml文件中
var chromeOptions = new ChromeOptions();
chromeOptions.AddArguments("test-type");
chromeOptions.AddArguments("--disable-extensions");
chromeOptions.AddArguments("no-sandbox");
var driver = new ChromeDriver(chromeOptions);
如何在xml文件中保存数据。
这段代码不起作用..
我已经获取了列表private const string XmlFile = "Order.xml";
private async void btncalculate_Click(object sender, RoutedEventArgs e)
{
ClsOrder ord = new ClsOrder();
ord.Id = 1;
ord.package = str;
ord.Domestic = strchk;
List<ClsOrder> ordlist = await getXmlorderlist();
ordlist.Add(ord);
using (var stream = await ApplicationData.Current.LocalFolder.OpenStreamForWriteAsync(XmlFile, CreationCollisionOption.ReplaceExisting))
{
var serializer = new DataContractSerializer(typeof(List<ClsOrder>));
serializer.WriteObject(stream, ordlist);
}
}
private async Task<List<ClsOrder>> getXmlorderlist()
{
await ApplicationData.Current.LocalFolder.CreateFileAsync(XmlFile, CreationCollisionOption.OpenIfExists);
var stream = await ApplicationData.Current.LocalFolder.OpenStreamForReadAsync(XmlFile);
if (stream.Length == 0)
return new List<ClsOrder>();
DataContractSerializer serializer = new DataContractSerializer(typeof(List<ClsOrder>));
List<ClsOrder> ordlist = (List<ClsOrder>)serializer.ReadObject(stream);
return ordlist;
}
中的所有数据,我想将数据保存在xml中。