Transferred from: http://www.cnblogs.com/sifenkesi/archive/2012/03/12/2391330.html
There is a slight difference in how XML files are read on the PC and on iOS, and it is tested that the following methods are not supported for loading XML files on iOS:
XmlDocument xmldoc = new XmlDocument ();
Xmldoc.load ("Assets/resources/text.xml");
There are 2 correct ways to upload XML into iOS:
(1) Method one
Textasset Textasset = (textasset) resources.load (filename, typeof (Textasset));
XmlDocument xmldoc = new XmlDocument ();
Xmldoc.load (new StringReader (Textasset.text));
(2) Method two
Textasset Textasset = (textasset) resources.load (filename, typeof (Textasset));
XmlDocument xmldoc = new XmlDocument ();
Xmldoc.loadxml (Textasset.text);
The above 2 methods use the XmlDocument load () method and the Loadxml () method respectively, the parameters passed some differences, but all need to pass the Resources.load () method to first load the file into a textasset, Then pass the Load method to xmldoc.
(3) method three
Files that need to be persisted on the ipad, such as the game's local archive, cannot be stored in the resources directory because it cannot be written on the ipad.
So what should you do with the read and write XML on the ipad? The method is described as follows:
Store the files that need to be serialized in the Application.persistentdatapath directory, which is a platform-dependent path.
Write:
XmlDocument xmldoc = new XmlDocument ();
...
Xmldoc.save (application.persistentdatapath+ "//abc.xml");
Read:
XmlDocument xmldoc = new XmlDocument ();
Xmldoc.load (application.persistentdatapath+ "//abc.xml");
PS1:
There is another way to implement local persistence, using the Playerprefs class, which is the class provided by u3d specifically for player preferences, but I'm not using this class for the time being, and it's not easy to test yet.
PS2:
For Android platforms: Use the above method (3), which is the same as the iOS platform.
For Mac platforms: Use the above method (1)/(2).
For Windows platforms: Use the above method (1)/(2).
U3d How to load XML files on different platforms--ios MAC Android