我在使用XmlWriter中的Create方法时遇到了问题。即使我使用msdn上的示例,它也无法正常工作。http://msdn.microsoft.com/en-us/library/kcsse48t.aspx
我创建了一个“空白页”项目,用于Windows商店应用程序。我在其中插入了来自msdn的示例代码,以测试XmlWriter类的工作方式。
VS给我报错:
VS给我报错:
Cannot resolve method 'Create(string)', candidates are:
System.Xml.XmlWriter Create(System.IO.Stream) (in class XmlWriter)
System.Xml.XmlWriter Create(System.IO.TextWriter) (in class XmlWriter)
System.Xml.XmlWriter Create(System.Text.StringBuilder) (in class XmlWriter)
System.Xml.XmlWriter Create(System.Xml.XmlWriter) (in class XmlWriter)
在控制台应用程序中,这个代码没有问题。但我需要创建一个Windows商店应用程序。
我的目标是向现有的xml文件添加内容。
有人可以告诉我为什么这个代码不起作用,或者如何用其他方式实现我的目标吗?
谢谢您的时间。
编辑:
抱歉,这是我的代码:
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Runtime.InteropServices.WindowsRuntime;
using System.Xml;
using System.Xml.Linq;
using Windows.Data.Xml.Dom;
using Windows.Foundation;
using Windows.Foundation.Collections;
using Windows.UI.Xaml;
using Windows.UI.Xaml.Controls;
using Windows.UI.Xaml.Controls.Primitives;
using Windows.UI.Xaml.Data;
using Windows.UI.Xaml.Input;
using Windows.UI.Xaml.Media;
using Windows.UI.Xaml.Navigation;
// The Blank Page item template is documented at http://go.microsoft.com/fwlink/?LinkId=234238
namespace DatabaseTest
{
/// <summary>
/// An empty page that can be used on its own or navigated to within a Frame.
/// </summary>
public sealed partial class MainPage : Page
{
public MainPage()
{
this.InitializeComponent();
}
private void button_submit_Click(object sender, RoutedEventArgs e)
{
using (XmlWriter writer = XmlWriter.Create("output.xml"))
{
writer.WriteStartElement("book");
writer.WriteElementString("price", "19.95");
writer.WriteEndElement();
writer.Flush();
}
}
}
}