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 ""; } (编辑:李大同)
【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!
|