Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 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
0
Question by suwandy · Aug 02, 2017 at 03:40 PM · mobile devices

Android read/write .xml file from persistent-path

Thanks in advance for reading this question.

I'm having trouble reading/writting xml file on android devices. My game require read/write .xml file to function properly. So far i've successfully reading the xml content, but failed to overwrite/save the file. I've already set the Player Settings > Write Permission > External. I've also copied the .xml file to Android > data > com.myCompany.myTitle > files. This is some way that i tried to read the .xml file:

  1. Using Streaming Datapath and www, i could read the xml content from www.text property

  2. Using Persistent Datapath, i could check the file exist from Application.persistentDataPath + "/DataPlayer.xml". But,i cannot retreive its content.

  3. Using Resources.Load ("Resources" folder), i could read the xml content. But it seems pre-compiled so the .xml file cannot be edited (please correct me if i'm wrong).

  4. Using Public TextAsset and assign the xml through unity editor manually (Without "Resources" folder). Then Resources.Load could get its content just like method no.3

The way i'm reading the .xml file was by using XmlDocument with LoadXml(string content) method. Then, i modify the XmlDocument and finally call Save(string path) method. I used the Persistent Datapath as parameter, but what happened next was the xml file become corrupted (size become 0B). My attempt to overwrite the file has been unsuccessful so far.

Some discussion suggest using Persistent Datapath for deploying to mobile platform, but i can't seem to get it right. Others suggest doing serialize / deserialize, but i'm not quite understand the concept behind it.

Thank you again for reading all this. I hope someone could enlighten me on this matter.

Comment
Add comment
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

1 Reply

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

Answer by Bieere · Aug 02, 2017 at 06:31 PM

If you're looking for an alternative solution to the XML document, assuming you're not attempting to change any Android specific files, try using JSON:

  • LITJSON

  • Json Utility

Essentially would be doing some of the same function as the XML from what i gather.

But back to your issue, it might be worth trying to use some of the function within System.IO to save the file as it does provide some functionality for overwriting files implicitly or manually

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 suwandy · Aug 03, 2017 at 03:44 AM 0
Share

Thank you Bieere for your answer. I appreciate the JSON suggestion. Personally, i've never tried JSON so it's gonna took some time learning it. As of now, the project schedule on the tight spot so i'm gonna stick with X$$anonymous$$L for now. I'll test your suggestion using System.IO. I'll let you know when i've got the result.

avatar image suwandy · Aug 03, 2017 at 02:09 PM 0
Share

I've tried your suggestions. The WriteAllText or AppendAllText didn't work at all. It didn't even trigger exception catch. $$anonymous$$eanwile, StreamWritter trigger exception IOException: Sharing violation on path. I've tried closing all program that access the file, but the process still corrupt the file into 0B. Both way were unsuccessful.

avatar image Bieere suwandy · Aug 03, 2017 at 03:55 PM 1
Share

So from this point, i would suggest 2 more things to try.

  1. Check out this link and see if these techniques for Reading/Writing help

  2. Ensure that the External write permission is actually within the manifest

avatar image suwandy suwandy · Aug 04, 2017 at 02:54 PM 0
Share

That link works for me! Thank you Bieere for your support these 2 days. However, upon successfully loading and saving the file, it still become 0B in size. I tried opening the xml file from PC. It opened but the edited part seems cropped out. From Android device explorer i check the xml file properties and it shows 0B in size. I tried opening it using default app from android, but it showed nothing, blank. $$anonymous$$eanwhile, through debugging the apps and checking InnerXml properties, it does correctly show the xml file content and all the edit that i've done. How come this happen?

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

68 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 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 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 avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

How to rotate a 2D object (ex. log) with rigidbody2D based on touchPosition 1 Answer

How do you get the Standard Shader to work on iOs 9?, 2 Answers

Android Back (or Escape) button isn't being recognized. 3 Answers

How to make the back image appear before the front image where it is scratched? 0 Answers

Camera with Depth Only Clear Flags does not work on Mobile Devices 0 Answers


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