U3d How to load XML files on different platforms--ios MAC Android

Source: Internet
Author: User

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

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.