I’m developing an Android app at the moment and need to load unit data. I chose xml files to store this data, and it works perfectly fine on PC.
On Android it doesn’t work and I guess the reason for that is the way I load the xml files frm the resource folder:
I’ve just been struggling with this problem as well. It turns out that in order to read XML data on an Android device, you need to load the TextAsset from your Resources folder.
1.) Create a folder in your Assets folder named Resources and place your XML file into that folder.
2.) Load the TextAsset using Resources.Load(). Use the name of the file without adding the extension (e.g., “firstlevel”) and cast it as a TextAsset.
3.) Create an XmlSerializer for your class (my class type was Map, yours will probably be different)
4.) Then create a stream for your code to Deserialize your XML code.
TextAsset levelXML = (TextAsset)Resources.Load("FileNameWithoutExtension", typeof(TextAsset));
XmlSerializer serializer = new XmlSerializer(typeof(Map));
using (var stream = new MemoryStream(levelXML.bytes)) {
map = (Map)serializer.Deserialize(stream);
}