- Home /
Get external .xml in mobile
Hey guys, I recently asked about an error I've got when try to get an external .xml file in mobile. I got an answers, understood my problem, but I couldn't get forward with the problem's fix.
I have the .xml placed in the Resources folder, but I don't know how to get this files as .xml files with Resources.Load in order to read this file using XmlReader.Read();
The best would be if I could get the path for this .xml in the mobile, so I could use XmlReader.Create(thisPath);
But I definitely got stuck in this and I can't get any results!
Anyone knows a way to go through this?
Thanks from now!
Answer by Mortoc · Jun 26, 2012 at 04:29 AM
You'll want to load the xml file as a Unity TextAsset
Then pass the text property from that to XmlReader.Create()
Hmm, that's interesting! I'll check it out in a $$anonymous$$ute and come back to post what I get. :)
Actually, I'm getting a null reference exception error in the line where I call the print.
void Awake () {
_language$$anonymous$$anager = this;
DontDestroyOnLoad(this);
languageFiles = new TextAsset[3];
languageFiles[0] = Resources.Load("arachnaZone_EN.xml") as TextAsset;
languageFiles[1] = Resources.Load("arachnaZone_PTBR.xml") as TextAsset;
languageFiles[2] = Resources.Load("arachnaZone_SN.xml") as TextAsset;
print(languageFiles[0].text);
}
I have the folder 'Resources' in the Assets folder with these 3 .xmls in it.
Without the .xml extension it worked! Thanks!
Anyway, when calling XmlReader reader = XmlReader.Create( languageFiles[(int)_curLanguage].text); I get the following error:
ArgumentException: Illegal characters in path.
Anyway, when calling XmlReader reader = XmlReader.Create( languageFiles[(int)_curLanguage].text); I get the following error: ArgumentException: Illegal characters in path.
Per the XmlReader.Create docs, passing a string to `XmlReader.Create()`, "Creates a new XmlReader instance with specified URI"; `XmlReader` interprets `languageFiles[0].text` as the path to the text file rather than the contents of the file, which is why you are getting an exception for "Illegal characters in path". Ins$$anonymous$$d, you should interpret `languageFiles[0].text` as a text stream first, and pass that to `Create()`.
Try using the System IO namespace in the file and change your code above to
XmlReader reader = XmlReader.Create( new StringReader(languageFiles[(int)_curLanguage].text))
Your answer
Follow this Question
Related Questions
read XML work in editor but not in final build 2 Answers
Play an array of audioclips from HDD. 1 Answer
Reading XML Data C# 2 Answers
Read STRING AS XML TO SHOW LIST 1 Answer
pixel terrain texture mobile 0 Answers