Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 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 /
This question was closed Nov 19, 2015 at 09:15 PM by LiveWire for the following reason:

Other

avatar image
0
Question by LiveWire · Aug 16, 2013 at 03:57 AM · androidxmlsave-to-file

Loading/Saving XML not working on Android

I am attempting to read in data from an XML file, modify that data, then save the file. The following code works perfectly fine on PC, but does not work when I test it on Android. Can anyone explain where I've gone wrong?

On Android, the filepath string ends up being: /data/data/com.unity3d.player/files/save_data.xml However, if I do a check to see if a file exists at that location it comes back false.

 public void WriteStarGemData(string gem)
     {
 
         string filepath = Application.persistentDataPath + "/save_data.xml";
         Debug.Log(filepath);
         XmlDocument xmlDoc = new XmlDocument();
 
         if (!File.Exists(filepath)) //if the file does not exist at Application.persistentDataPath, create it
         {
             xmlDoc.Load(Application.dataPath + "/Resources/save_data.xml");
             xmlDoc.Save(filepath);
         }
         else
         {
             xmlDoc.Load(filepath);
 
             XmlNodeList nodelist = xmlDoc.SelectNodes("Root/STAR_GEMS/String"); //get a list of all the Star Gem nodes in the file
             foreach (XmlNode node in nodelist)
             {
                 if (node.Attributes["key"].Value == gem) //if supplied string matches the key, swap it's value
                 {
                     if (node.Attributes["value"].Value == "false")
                         node.Attributes["value"].Value = "true";
                     else
                         node.Attributes["value"].Value = "false";
 
                     break;
                 }
             }
             xmlDoc.Save(filepath);
         }
     }
Comment
Add comment · Show 3
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 Frankzhang_1229 · Sep 03, 2014 at 05:48 AM 0
Share

Hi,I come across the same problem just like yours. Could I know how you figured it out ,please? I run the program well on PC,but it doesnt work on Android. I really need your help. Thank you very much.

avatar image mohamedrashad · Nov 19, 2015 at 05:58 PM 0
Share

try to add xml file in Resources folder and load xml file using this code.

   TextAsset textAsset = (TextAsset)Resources.Load("xml file name without extension", typeof(TextAsset));
    XmlDocument xmlDocument = new XmlDocument();
    xmlDocument.LoadXml(textAsset.text);

avatar image MakinStuffLookGood · Nov 19, 2015 at 06:00 PM 0
Share

This appears to be a duplicate of: http://answers.unity3d.com/questions/203852/how-to-access-persistent-data-path-in-android-phon.html?redirectedFrom=516584

But that post is pretty old and hasn't marked the answer as correct. Could you please try that top solution, and if it works, come back and post the answer/mark yourself as correct?

0 Replies

  • Sort: 

Follow this Question

Answers Answers and Comments

18 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

Related Questions

Android Persistant Data 1 Answer

Load file on Android 1 Answer

xmlDocument.loadXml/load raises NotImplementedException on android, works in editor 1 Answer

Android and XML (Reading/Wirting) 1 Answer

android xml language issue 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