Read xml file in Android/Mono

随声附和 提交于 2019-12-12 01:29:19

问题


I'm trying to read an xml file which I plan to include as part of my mobile application. I've created a folder called "XML" and added a file called "test.xml". The files build action is set to content. When I run the app it crashes on trying to find the file. Here is the code I'm using:

_path = "XML/test.xml";
doc = new XmlDocument();
doc.Load(_path);

Here is the error I get:

System.IO.DirectoryNotFoundException has been thrown.

Could not find a part of the path "/XML/test.xml"

Do I need to register the directory/folder somehow? Thanks for any advice, I'm sure I've just missed something simple...


回答1:


Do you mean that you'd created XML directory inside of your project?

If you want to include XML to your APK - one of the best ways will be to create /res/xml/file.xml and read it inside application with Resources class. Please have a look at this thread - maybe you'll find it helpful. Open XML file from res/xml in Android Good luck



来源:https://stackoverflow.com/questions/12236208/read-xml-file-in-android-mono

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!