使用 Untiy读取XML,读取成功关键在与17~19这三行,一定要跳过BOM,要不然就一直获取不到值。
IEnumerator LoadXml( string filePath, string imageName)
{
WWW www = new WWW(filePath);
yield return www;
//Debug.Log(www.text);
if (www.error != null)
{
print("The request failed");
}
else
{
print("The request is successful");
//创建
XmlDocument XmlDoc = new XmlDocument();
//跳过BOM
System.IO.StringReader stringReader = new System.IO.StringReader(www.text);
stringReader.Read();
string result = stringReader.ReadToEnd();
//关闭
stringReader.Close();
//加载文本
XmlDoc.LoadXml(result);
//获取节点个数
int XmlCount = XmlDoc.GetElementsByTagName("JD").Count;
for (int i = 0; i < XmlCount; i++)
{
if (XmlDoc.

本文介绍如何在Unity中有效读取XML文件,重点强调需要跳过BOM以避免无法获取XML数据的问题。
最低0.47元/天 解锁文章
5559

被折叠的 条评论
为什么被折叠?



