- Home /
How to add xml to project build
Hi Everybody. I have a trouble: I load translations for game from xml file. To read data from XML I use System.XML parsing. I have put my xml file in "Assets/Translations/translations.xml". When I try it in Unity all is fine, however when I build it for Android. There is no translations.xml file in my .apk. How Can I add my file to a build? Thank you!
How do you load xml file? From WWW class or you create script and it create public TextAsset variable?
I load it using System.X$$anonymous$$L; libraries:
var serializer = new XmlSerializer (typeof(TranslationsContainer));
var stream = new FileStream ((Application.dataPath + PATH), File$$anonymous$$ode.Open);
TranslationsContainer container = serializer.Deserialize (stream) as TranslationsContainer;
stream.Close ();
I found in this article that there is no physical text file included to the build in any case. In my game was a problem to load xml, thats why I thought that file was not included. I unpacked apk and didn't find there my xml, and tried to include xml. Now I will try another way to resolve my problem.
Answer by KurtGokhan · Jan 18, 2015 at 09:54 AM
Move it under Assets/Resources folder. You can load it with:
TextAsset myText = Resources.Load("filenameWithoutExtension") as TextAsset;
// use myText.text to load into xml
Reference: http://docs.unity3d.com/Manual/class-TextAsset.html