我遇到了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