如何在我的项目解决方案中从我的手机的应用程序目录中加载更新的xml文件

时间:2016-04-18 11:36:23

标签: android xpath xamarin xamarin.android filepath

我已经更改了XML属性并保存了文件保存在手机路径中的App目录中的XML文件是“Android / data / data / App17.App17 / files”现在我想在我的项目中加载这个更新的XML文件我怎么能这样做

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);
            var xml = XDocument.Load(Assets.Open("Q317664.xml"));
            var node = xml.Descendants("Book").FirstOrDefault(cd =>        cd.Attribute("Id").Value == "1");
            node.SetAttributeValue("ISBN", "new");

            string dir = System.Environment.GetFolderPath(System.Environment.SpecialFolder.Personal);
            string path = Path.Combine(dir, "Q317664.xml");
        }
    }
}

1 个答案:

答案 0 :(得分:0)

var path = Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData);
var filename = Path.Combine(path, "Q317664.xml");

var xmlString=File.ReadAllText(filename);
XDocument doc = XDocument.Parse(xmlString);

XML将被加载到doc实例。