Load from XML on iPhone

Hi Everyone,

I am having trouble loading from XML on the iPhone. Here is the code:

function LoadXML()
{
   var r : StreamReader = File.OpenText(docPath+"/highscores.xml");
   var _info : String = r.ReadToEnd();
   r.Close();
   line=_info;
   highscores = line.Split("%"[0]);
   Debug.Log("File Read");
}

Here is the error I am getting:

DirectoryNotFoundException: Could not find a part of the path "/var/mobile/Applications/F0571EFE-3482-4183-8A8B-4F3498FB14FD/terraslam.app/highscores.xml".

I am placing the xml file straight in the assets folder. Where should I be putting it? or is the code wrong?

For reference this is also the code I am going to use to write to the XML. I am assuming this is wrong as well if the first bit is.

function CreateXML()
{
   var writer : StreamWriter;
   var t : FileInfo = new FileInfo(docPath+"/highscores.xml");
   if(!t.Exists)
   {
      writer = t.CreateText();
   }
   else
   {
      t.Delete();
      writer = t.CreateText();
   }
   writer.Write(lineToWrite);
   writer.Close();
   scoreText.text = "File written.";
}

Any help appreciated!!!

Thanks

Chris

the path is totally wrong I fear, that path is not writeable at all. On the iphone you only have 2 folders you can write to: The apps document folder and the apps cache folder

if you want the file to be writeable you must create it yourself manually in the applications Docs directory. There are a few threads on the board and potentially also some answers here on how to generate the applications doc path from the dataPath and I additionally posted some short native code for objc - uikit to return the real one (the example there though is for the cache path, but the docs is the same with the constant replaced) directly as provided by iOS which will always, independent of changes on unity and iOS, give you the correct code.