您的位置:首页 > 移动开发 > Unity3D

Unity3D读取XML内容代码

2014-08-06 14:04 141 查看

Unity3D读取XML内容代码

一个简单读取Unity3D中XML内容的代码:

public string showXml(string temp)

{

UnityEditor.AssetDatabase.Refresh();

string filepath = Application.dataPath + "/my.xml";

string tempText = "";

print("a");

print(File.Exists(filepath).ToString());

if (File.Exists(filepath))

{

print("b");

XmlDocument xmlDoc = new XmlDocument();

xmlDoc.Load(filepath);//若要读网络 前面改成IEnum线程这里改网络xml地址即可

XmlNodeList nodeList = xmlDoc.SelectSingleNode("main").ChildNodes;

//

foreach (XmlElement xe in nodeList)

{

// Debug.Log(xe.GetAttribute("name"));

// Debug.Log(xe.Name);

foreach (XmlElement x1 in xe.ChildNodes)

{

if (x1.Name == temp)

{

tempText= x1.InnerText;

// print(x1.InnerText);

}

}
}

return tempText;

print(tempText);

}

else

{

return "file not exists!";

}

// return "";

}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: