I can load xml data, but I can't to save it, Here the script

I was working with Stream system, but when I to build an apk, it didn’t work, I couldn’t to get my database data, and I don’t sure if I could to put a new data with Stream system, so I change to StringWriter and now my phone can get the database data, but now I don’t know how to save new data.
I know i need something but I don’t get it, I was searching information but unitl now I havent got an answer

By the way I saw one way using binary system, but I would like to resolve my problem, if I don’t found an answer I gonna take that alternative

here an alternative using Serialization Binary :
https://forum.unity.com/threads/reading-xml-files-works-on-pc-but-not-on-android.412851/

althoug I havent test it, so I don’t sure if that way can to work with my problem, even so I wanna to get an answer using the StringWrite System

StringWriters are for writing strings not files. (the clue is in the name)

You should probably use StreamReader/Writers instead and be trying to fix the initial bug you had.

@amarellano196
There isnt an actual “Resources” folder available in build, so it is not recommended to save data in a file present in Resources Folder.
I would recommend saving and loading files from Application.persistentDataPath.

 filePath = Path.Combine(Application.persistentDataPath, "xml_data.xml");
 void Start(){
     if (!File.Exists(filePath))
     {
       SaveData();
     }
 }

void SaveData()
{
    var serializer = new XmlSerializer(typeof(riaz));
    using (var stream = new FileStream(filePath, FileMode.Create))
    {
        serializer.Serialize(stream, databaseXml);
    }
}

 void LoadData()
 {
        string text = File.ReadAllText(filePath);
        XmlSerializer serializer = new XmlSerializer(typeof(raiz));
        using (StringReader reader = new StringReader(text))
        {
            databaseXml = (serializer.Deserialize(reader)) as raiz;
        }
    }

For more info, check http://codesaying.com/parse-xml-in-unity3d/