我遇到了XmlWriter中的Create方法问题。使用XmlWriter创建xml文件
即使当我使用msdn的例子,它将无法正常工作。 http://msdn.microsoft.com/en-us/library/kcsse48t.aspx
我为Windows应用商店应用程序创建了一个“空白页面”项目。 其中,ive插入了来自msdn的示例代码,以测试XmlWriter类的工作方式。
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();
}
}
}
}
显示您的代码。 – 2014-10-16 11:36:32
和完整的错误信息 – Vladimirs 2014-10-16 11:38:03
对不起,添加了我的代码。 – 2014-10-16 11:41:14