is it impossible to read XML within ANDROID's jar file?
Hi everyone! Since today I am starting to feel real desperate. I've spent more than 3 weeks trying to read an .xml file on ANDROID. I've tried so many ways that I don't care which method to use anymore, I'll be happy to use any that actually works. I tried to rename the exstention from .xml to .txt, but it didn't work. I am using two languages and I need to load two different .xml files. I am using GetElementById() method. Here is my code. If anyone knows anything, or if any of you made it work, please I beg you give me a hint. Thank you!
using UnityEngine;
using TMPro;
using System;
using System.Xml;
public class Localization : MonoBehaviour
{
/// <summary>
/// created 17.02.2019
/// </summary>
private string eng_file_name = "eng_text";
private string rus_file_name = "rus_text";
private string curr_file_name;
public TMP_Text my_text;
private string curr_player_name;
private string curr_language;
private void Start()
{
ChangeLanguage();
}
public void ChangeLanguage()
{
curr_player_name = PlayerPrefs.GetString("player_name");
GetSetLanguage();
LoadData();
}
private void GetSetLanguage()
{
if (PlayerPrefs.HasKey("SettingsLanguage" + curr_player_name))
curr_language = PlayerPrefs.GetString("SettingsLanguage" + curr_player_name);
else
curr_language = "eng";
if (curr_language == "eng")
curr_file_name = eng_file_name;
if (curr_language == "rus")
curr_file_name = rus_file_name;
else
curr_file_name = eng_file_name;
}
private void LoadData()
{
try
{
TextAsset text_asset = (TextAsset)Resources.Load(curr_file_name, typeof(TextAsset));
XmlDocument doc = new XmlDocument();
doc.LoadXml(text_asset.text);
XmlElement my_text_id = doc.GetElementById("my_text");
my_text.text = my_text_id.InnerText;
}
catch (Exception error)
{
Debug.LogException(error, this);
return;
}
}
}
Here is my XML file example:
<?xml version="1.0" encoding="utf-8" ?>
<!DOCTYPE eng_text [
<!ELEMENT eng_text ANY>
<!ELEMENT string ANY>
<!ATTLIST string id ID #REQUIRED>
]>
<!-- created 17.02.2019-->
<eng_text>
<string id ="my_text">
<![CDATA[My_text]]>
</string>
</eng_text>
When I open my APK build, i can't find there any xml files or Resources folder, where I put my xml files, only resources.arsc file. What do I do wrong? How can I make it work on ANDROID device? Please help...