Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 14 Next capture
2021 2022 2023
2 captures
13 Jun 22 - 14 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
2
Question by Rosonator · Jan 09, 2013 at 04:07 PM · androidloadxmlresources

XML Loading works in PC... but not in Android

Hello everybody,

When I run my application in the Editor everything works fine. I load an XML this way:

 xmlPreguntas.Load(Application.dataPath.ToString() + "/Resources/xxxxxxx.xml");


Then, I compile to Android, but hte XML document doesn't load.

I was not sure why was this happening, but I read somewhere something that should work for me, loading by Resources.Load(). I tried that way typing this:

 TextAsset textAsset = (TextAsset) Resources.Load("xxxxxx.xml");
 XmlDocument xmlPreguntas = new XmlDocument();
 xmlPreguntas.LoadXml(textAsset.text);

This code, instead, doens't work nor in the Editor. The error shown is the next: NullReferenceException: Object reference not set to an instance of an object, refering the last line. I thinks it's telling me that the loading is failing, but I don't really know why.

Hope there's somebody smarter than me able to help me.

Greetings,

Alex.

Comment
Add comment · Show 2
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image 4nobodyman · Apr 10, 2015 at 06:04 AM 0
Share

Load wotks is great! but TextAsset is only read how i can load and save xml file?

avatar image Graham-Dunnett ♦♦ 4nobodyman · Jun 07, 2014 at 10:22 AM 0
Share

Resources is read-only. So write the X$$anonymous$$L out to the file system using StreamWriter.

3 Replies

· Add your reply
  • Sort: 
avatar image
11
Best Answer

Answer by liszto · Jan 09, 2013 at 04:09 PM

do you try to load your xml with the second method but without the extension ?

Something like this :

 TextAsset textAsset = (TextAsset)Resources.Load("FileNameWhitoutFileExtention", typeof(TextAsset));
 XmlDocument xmldoc = new XmlDocument ();
 xmldoc.LoadXml ( textAsset.text );

 
Comment
Add comment · Show 4 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image Rosonator · Jan 09, 2013 at 04:40 PM 1
Share

oh! When I first saw that "without extension" i thought in the path. Let me try!

avatar image Rosonator · Jan 09, 2013 at 05:05 PM 0
Share

You did it! Thank you very much, listo!

avatar image gearpichon · Apr 29, 2014 at 05:34 AM 1
Share

how can i do it with a relative path?? I don't want the xml file in the resources folder. help!

avatar image iamkhova · Dec 28, 2014 at 06:49 AM 0
Share

This worked for me.. but I initially missread it. In your resource folder keep the .xml extension on your file name but in your code accessing it leave the extension off. It will auto find the .xml. I erased the xml extension from my file name and had a lot of grief trying to figure out why this did not work.

avatar image
0

Answer by wildikon · May 12, 2014 at 12:30 PM

Hi,

having the same issue loading XML (works on PC but not on my android device)

When I use the code |

TextAsset textAsset = (TextAsset)Resources.Load("FileNameWhitoutFileExtention",typeof(TextAsset));

I keep getting an error, saying line (63,18): UCE0001: ';' expected. Insert a semicolon at the end

??? this is driving me a little bit insane, what am I missing here?

thanks for any help offered!

Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image
0

Answer by koslovdenis · Mar 08, 2019 at 12:56 PM

I can't seem to work it out in 2019, in unity 2018.3. ANd i can't understand why... Although I am trying to access my .xml file with GetElementById() method. My curr_file_name string variable is assigned runtime in the code (my game has 2 languages so I need to load different files) and it doesn't have an extention.

 TextAsset textAsset = (TextAsset)Resources.Load(curr_file_name, typeof(TextAsset));
 XmlDocument doc = new XmlDocument();
 doc.LoadXml(textAsset.text);
     
 XmlElement greeting_word_id = doc.GetElementById("greeting_word");
 greeting_word = greeting_word_id.InnerText;

Anyway. I compiled this code and I opened an APK file with zip. No xml files were there. What am I doing wrong? Please if anyone could work it out tell me HOW? I am struggling with this over a few weeks in a row... and I am getting really crazy. Thank you..

Comment
Add comment · Show 3 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image flaxibitz · Aug 19, 2021 at 01:21 PM 0
Share

@koslovdenis were you able to solve the problem as I have the same issue now. Kindly help someone. The game loads well in editor but not on the build apk. What am I doing wrong. I used the same code above.

avatar image Bunny83 flaxibitz · Aug 19, 2021 at 03:56 PM 0
Share

Please don't necro post on such an ancient question. Especially you have commented on an answer that is not an answer but also a question. koslovdenis hasn't been online since end of March 2019, so it's unlikely he will respond. Also his answer-question doesn't really say what doesn't work. Of course there will be no xml file inside the apk since TextAssets are assets and are packed into asset files which form Unity's asset database. Who knows what actual issue he had.


If you have a problem or a question, please ask your own question. When you do so, add more information. What have you done, what did you expect to happen, what happens instead, What observations have you made, ....

avatar image flaxibitz Bunny83 · Aug 19, 2021 at 05:18 PM 0
Share

I have already asked a question on this. And didn't get any working answer. So I figured since this worked for others I might as well ask here. You might as well help with $$anonymous$$e using the link below. https://answers.unity.com/questions/1854198/i-have-a-quiz-game-that-loads-questions-using-an-x.html.

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

19 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Load from Xml on Iphone and Android 2 Answers

build android apk that contain Resource XML 0 Answers

Can gameobject be exported as unity3d form? 0 Answers

Load Xml on Android with XmlReader 2 Answers

Save and Load data from Local XML file won't work 1 Answer


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges