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 /
avatar image
1
Question by nypraise · Mar 13, 2014 at 08:54 PM · iosxmlpath

Writing a XML file to iOS

I am trying to write to a XML on iOS, but it seems to be impossible. Tried several different this but none have worked.

I have read that iOS only have write access to it´s /Documents folder, so I have tried to set a Application.dataPath to the Documents folder. But I get this error in Xcode :

 DirectoryNotFoundException: Could not find a part of the path "/Users/mariusmathisen/Library/Application Support/iPhone       Simulator/7.1/Applications/6AE4AF70-EFDF-46F0-9947-5C0936F3AD27/DaXml.app/Data/Documents/gamexmldata.txt".

This is my code to write to XML :

 blic void WriteToXml()
     {
         Debug.Log ("Du nådde metoden");
         //string filepath = Application.dataPath + @"/Data/gamexmldata.xml";
 
         XmlDocument xmlDoc = new XmlDocument();
 
 
         GameControl.control.outputXml = "Du nådde WriteXML";
         if(File.Exists(Application.dataPath + "/Documents/gamexmldata.txt"))
         {
             Debug.Log("Filen Fantes");
             GameControl.control.outputXml = "DU ER I Writetoxml og filen fantes";
 
 
             
             xmlDoc.Load(Application.dataPath + "/Documents/gamexmldata.txt");
             //xmlDoc.Load(filepath);
             
             XmlElement elmRoot = xmlDoc.DocumentElement;
             
             // elmRoot.RemoveAll(); // remove all inside the transforms node.
             
             XmlElement elmNew = xmlDoc.CreateElement("rotation"); // create the rotation node.
             
             XmlElement rotation_X = xmlDoc.CreateElement("x"); // create the x node.
             rotation_X.InnerText = x; // apply to the node text the values of the variable.
             
             XmlElement rotation_Y = xmlDoc.CreateElement("y"); // create the y node.
             rotation_Y.InnerText = y; // apply to the node text the values of the variable.
             
             XmlElement rotation_Z = xmlDoc.CreateElement("z"); // create the z node.
             rotation_Z.InnerText = z; // apply to the node text the values of the variable.
             XmlElement navnElement = xmlDoc.CreateElement("name");
             navnElement.InnerText = navn;
 
             GameControl.control.inputXml = navnElement.InnerText;
 
             elmNew.AppendChild(rotation_X); // make the rotation node the parent.
             elmNew.AppendChild(rotation_Y); // make the rotation node the parent.
             elmNew.AppendChild(rotation_Z); // make the rotation node the parent.
             elmNew.AppendChild(navnElement);
             elmRoot.AppendChild(elmNew); // make the transform node the parent.
 
             xmlDoc.Save(Application.dataPath + "/Documents/gamexmldata.txt"); // save file.
             Debug.Log("Filen er lagret");
         }else{
 
             xmlDoc.Save(Application.dataPath + "/Documents/gamexmldata.txt");
         }
     }

Are there any suggestion to why I can´t get the XML to write to iOS and it´s folder? What am I doing wrong?

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 robertbu · Mar 13, 2014 at 08:54 PM 1
Share

Try Application.persistentDataPath.

avatar image nypraise · Mar 13, 2014 at 10:12 PM 0
Share

I still get the same error :

 XmlException: Document element did not appear. file:///Users/mariusmathisen/Library/Application Support/iPhone Simulator/7.1/Applications/6AE4AF70-EFDF-46F0-9947-5C0936F3AD27/Documents/gamexmldata.txt

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by whydoidoit · Mar 13, 2014 at 10:42 PM

If you want to use "Documents" under Application.persistentDataPath you would need to create that directory. Otherwise just use the path itself as that is where the device can write.

Also check out http://wiki.unity3d.com/index.php?title=Save_and_Load_from_XML and http://unitygems.com/xml

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

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

21 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

Related Questions

Write and Read to a iOS device! Help 1 Answer

moving to iOS- XML files 2 Answers

iPhone/iOS File URLs 1 Answer

XmlException when trying to read/write XML from iOS device 1 Answer

How to check the path on Android 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