Ich stehe vor dem Problem, wenn ich versuche, die XML-Datei zu speichern. Ich speichere die XML-Datei im Assets-Ordner und setze Build-Aktion auf Android Assets, aber wenn xml.Save ("Q317664.xml") ; Linie kommt gibt es Ausnahme System.UnauthorizedAccessException: Zugriff auf den Pfad „/Q317664.xml“ ist denied.i bin nicht sicher, warum dies auftrittDie Änderungen in der XML-Datei können nicht gespeichert werden
using System;
using Android.App;
using Android.Content;
using Android.Runtime;
using Android.Views;
using Android.Widget;
using Android.OS;
using System.IO;
using System.Reflection;
using Android.Content.Res;
using System.Xml;
using System.Xml.Linq;
using System.Xml.XPath;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace App17
{
[Activity(Label = "App17", MainLauncher = true, Icon = "@drawable/icon")]
public class MainActivity : Activity
{
int count = 1;
protected override void OnCreate(Bundle bundle)
{
base.OnCreate(bundle);
// Set our view from the "main" layout resource
SetContentView(Resource.Layout.Main);
// Get our button from the layout resource,
// and attach an event to it
var xml = XDocument.Load(Assets.Open("Q317664.xml"));
var node = xml.Descendants("Book").FirstOrDefault(cd => cd.Attribute("Id").Value == "1");
node.SetAttributeValue("ISBN", "new");
xml.Save("Q317664.xml");
// Button button = FindViewById<Button>(Resource.Id.MyButton);
// button.Click += delegate { button.Text = string.Format("{0} clicks!", count++); };
}
}
}
See: http://stackoverflow.com/questions/10562904/is-asset-folder-read-only –
@Morrison Chang Dann, wo ich so die XML-Datei speichern, dass i kann das Attribut der XML-Datei ändern, bitte helfen Sie mir –
Sie können XML als Datei in App-Verzeichnis speichern. – Sreeraj