How do I include XML files in an Android build?

How do I include XML files in an Android build?

I have a few XML files I want to include in a build of my game, and I want to have access to those XML files in Android. How to I store and load those XML files?


Answer 1:

You load XML files just like you would any other asset file. Review the documentation to learn about loading resources at runtime. Likely the easiest strategy will be to use Resource Folders:

To put anything into a Resource Folder, you simply create a new folder
inside the Project View, and name the folder “Resources”. You can have
multiple Resource Folders organized differently in your Project.
Whenever you want to load an asset from one of these folders, you call

An example of how you might use this to load an XML file:

TextAsset textAsset = (TextAsset) Resources.Load("MyXMLFile");  
XmlDocument xmldoc = new XmlDocument ();
xmldoc.LoadXml ( textAsset.text );