using UnityEngine; using System.Collections; using System.Xml; using System.IO; public class MyXmlRead : MonoBehaviour { void Start () { //定义了一个XmlDocument类的对象 XmlDocument xml = new XmlDocument (); //读取xml的一些设置 XmlReaderSettings set = new XmlReaderSettings (); //这个设置改为true的时候,不受xml文档中注释的影响 set.IgnoreComments = true; //Debug.Log (Application.dataPath); //用XmlDocument类的对象中得load方法,根据set设置,读取路径中的XMl字符串。 xml.Load(XmlReader.Create((Application.dataPath+"/Myxml.xml"),set)); //XmlNodeList类是Xml的节点类。 XmlNodeList xmlNodeList = xml.SelectSingleNode("cubes").ChildNodes; //输出Xml字符串中Cubes节点中子节点的个数 Debug.Log (xmlNodeList.Count); //遍历输出所有子节点的名字 foreach(XmlElement xe in xmlNodeList){ Debug.Log(xe.Name); } } } |
|