繁体   English   中英

如何在 UWP C# 中的 XDocument.Load 方法中给出 xml 文件路径

[英]How to give xml file path in XDocument.Load method in UWP C#

我在 Assets/Fonts/FontAwsome_version5.xml 有一个 XML 文件,我尝试使用以下方法读取此文件,但出现错误 - uri 前缀无法识别

XDocument xmlDocument = XDocument.Load(filePath); string filePath = "ms-appx:///Assets/Fonts/FontAwsome_version5.xml";

如何在 UWP C# 中的 XDocument.Load 方法中给出 xml 文件路径

I'm afraid you can't load the file with UWP uri scheme for System.Xml.Linq namespace api, for the requirement, you could use Windows Storage Api to open the file as stream then call XDocument load stream method to access the file's xml 内容。 对于测试,以下代码可以直接工作。

private async void Button_Click(object sender, RoutedEventArgs e)
{
   string filePath = "ms-appx:///Assets/Font.xml";
   var file =  await StorageFile.GetFileFromApplicationUriAsync(new Uri(filePath));
    using (var stream = await file.OpenStreamForReadAsync())
    {
        XDocument xmlDocument = XDocument.Load(stream);

    }
  
}

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM