This article loads local xml files
One: under pc platform
1: Whether it is persistentDataPath path or streamingAssetsPath, you can directly use load to get read and write access
eg: XmlDocument doc = new XmlDocument(); doc.Load(path);
2: One thing to note is that if you create a new folder to store xml files under the assets folder, then the xml in this folder cannot be read after packaging when packaging
Solution: 1: Put the xml file directly under the StreamAssets folder
2: After packaging, put the stored xml folder under your ****_Data folder (make sure the path is uniform, if your xml folder is not directly under the Assets folder, for example: Aeeets /Xml/ name .xml, then after packaging, create a new folder Xml under the ****_Data folder, and finally put name.xml in it)
3: Use the www class to load,
To use www to load xml files, you need to add "file://
eg.:
IEnumerator IEPCRead(string path)
{
WWW www = new WWW("file://" + path);
//do.......
}
Two: under the Android platform
1: You cannot directly load the xml under the streamingAssetsPath path , you can load the xml under the persistentDataPata path
eg.:
string path1 = Application.streamingAssetsPath + "/stream.xml";
XmlDocument doc = new XmlDocument();
doc.Load(path1); //错误
string path1 = Application.persistentDataPath + "/stream.xml";
XmlDocument doc = new XmlDocument();
doc.Load(path1);// 正确
2: Cannot read the xml under the folder created by yourself
This is the same as the second item under the pc platform, but we can't operate the apk after packaging, so don't create a folder to store the xml file under the android platform.
3: Use www to load
Use www to load the xml file, add "jar:file:// protocol
IEnumerator IEAndroidRead(string path)
{
WWW www = new WWW("jar:file://" + path);
//do.......
}
【modify】
ps: When I tried here, I found that streamingAssetsPath does not add "jar:file ://" protocol (it will cause errors if added)
date:2017.11.1
Add an example
Three: Summary
pc: You can directly load the xml file in the corresponding path, but you should pay attention to the error when you create the folder and read it after packaging
Add the "file://" protocol when loading with www
android: can only load the xml file under the persistentDataPata path, nothing else,
When loading with www, you need to add the "jar:file://" protocol, but streamingAssetsPath cannot add the "jar:file://" protocol