Windows Phone 8 응용 프로그램의 C#에서 로컬 XML 파일을 편집하려고합니다. 웹에서 AppendChild
과 같은 방법을 사용하여 XmlDocument
을 사용하여 수많은 예제를 발견했습니다. Windows Phone 8에서 XmlDocument
은 XDocument
으로, AppendChild
은 사라졌습니다. 나는 아래의 코드를 시도했지만 protected override void OnNavigatedTo(System.Windows.Navigation.NavigationEventArgs e)
에 약간의 오류가 발생합니다 : 오류는 여기에서 볼 수있다 : http://i811.photobucket.com/albums/zz38/JelleK1996/cerror1_zpsb6aa5398.pngC# (WP8)에서 Xml 파일 편집
누구든지 나를 도울 수 있습니까?
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Navigation;
using Microsoft.Phone.Controls;
using Microsoft.Phone.Shell;
using XmlLocalEdit1.Resources;
using System.Xml;
using System.Xml.Linq;
using System.Text;
namespace XmlLocalEdit1
{
public partial class MainPage : PhoneApplicationPage
{
// Constructor
public MainPage()
{
InitializeComponent();
// Sample code to localize the ApplicationBar
//BuildLocalizedApplicationBar();
}
protected override void OnNavigatedTo(System.Windows.Navigation.NavigationEventArgs e)
{
try
{
StringBuilder sb = new StringBuilder();
XmlWriterSettings xws = new XmlWriterSettings();
xws.OmitXmlDeclaration = true;
xws.Indent = true;
using (XmlWriter xw = XmlWriter.Create(sb, xws))
{
XDocument xdoc = XDocument.Load("Resources/bar.xml");
XElement xmlTree = new XElement("data",
new XElement("cocktail",
new XElement("name", "Dreamsicle"),
new XElement("id", 1)
)
);
xdoc.Add(xmlTree);
xdoc.Save(xw);
}
//xdoc.Add(xmlTree);
//xdoc.Save("Resources/bar.xml", SaveOptions.None);
}
catch (Exception myExc)
{
Console.WriteLine(myExc.Message);
}
}
/*private static XElement CreateCocktail(XDocument xmlDoc,
string name,
int id)
{
var xmlCocktail = xmlDoc
}*/
}
}
XML 파일 :
<?xml version="1.0" encoding="UTF-8"?>
<data>
<cocktail>
<name>43 Hedonism</name>
<id>14</id>
</cocktail>
<cocktail>
<name>B-52</name>
<id>4</id>
</cocktail>
</data>
'아래 코드를 시도했지만 보호 된 무효 보이드에서 오류가 발생했습니다.'- '일부 오류'란 무엇입니까? – DGibbs
오류 링크를 추가했습니다. http://i811.photobucket.com/albums/zz38/JelleK1996/cerror1_zpsb6aa5398.png – JelleKerkstra
xml 파일은 어디에 있습니까? 그것은 리소스에있는 것처럼 보이며 확실하지 않습니다. Windows Phone에서 파일을 편집 할 수 있습니다. 이 파일을 편집하려면 격리 된 저장소로 복사 한 다음 해당 복사본으로 작업해야합니다. – Olter