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 ""; }
原文链接:https://www.f2er.com/xml/298227.html