Android read/write .xml file from persistent-path

Thanks in advance for reading this question.

I’m having trouble reading/writting xml file on android devices. My game require read/write .xml file to function properly. So far i’ve successfully reading the xml content, but failed to overwrite/save the file. I’ve already set the Player Settings > Write Permission > External. I’ve also copied the .xml file to Android > data > com.myCompany.myTitle > files.
This is some way that i tried to read the .xml file:

  1. Using Streaming Datapath and www, i could read the xml content from www.text property
  2. Using Persistent Datapath, i could check the file exist from Application.persistentDataPath + “/DataPlayer.xml”. But,i cannot retreive its content.
  3. Using Resources.Load (“Resources” folder), i could read the xml content. But it seems pre-compiled so the .xml file cannot be edited (please correct me if i’m wrong).
  4. Using Public TextAsset and assign the xml through unity editor manually (Without “Resources” folder). Then Resources.Load could get its content just like method no.3

The way i’m reading the .xml file was by using XmlDocument with LoadXml(string content) method. Then, i modify the XmlDocument and finally call Save(string path) method. I used the Persistent Datapath as parameter, but what happened next was the xml file become corrupted (size become 0B). My attempt to overwrite the file has been unsuccessful so far.

Some discussion suggest using Persistent Datapath for deploying to mobile platform, but i can’t seem to get it right. Others suggest doing serialize / deserialize, but i’m not quite understand the concept behind it.

Thank you again for reading all this. I hope someone could enlighten me on this matter.

If you’re looking for an alternative solution to the XML document, assuming you’re not attempting to change any Android specific files, try using JSON:

Essentially would be doing some of the same function as the XML from what i gather.

But back to your issue, it might be worth trying to use some of the function within System.IO to save the file as it does provide some functionality for overwriting files implicitly or manually