Quantcast
Channel: Questions in topic: "ios"
Viewing all articles
Browse latest Browse all 4709

Writing a XML file to iOS

$
0
0
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?

Viewing all articles
Browse latest Browse all 4709

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>