搜集整理
public static XmlDocument LoadXML(string _xmllodepath)//PC
{
XmlDocument doc = new XmlDocument();
doc.Load(Application.streamingAssetsPath + _xmllodepath);
return doc;
}
/// <summary>
/// 加载XML数据
/// </summary>
/// <param name="xmlName"></param>
/// <returns></returns>
public static XmlDocument LoadXML(string xmlName)//安卓
{
XmlDocument doc = new XmlDocument();
TextAsset textAsset = Resources.Load(xmlName) as TextAsset;
XmlReader xmlReader = XmlReader.Create(new System.IO.StringReader(textAsset.text));
// doc.Load(_xmllodepath);
Debug.Log(textAsset);
doc.Load(xmlReader);
return doc;
}
/// <summary>
/// 解析XML数据
/// </summary>
public void ReadXml()
{
XmlDocument xmlDoc = LoadXML( "Data");
XmlNode xmlNodes = xmlDoc.SelectSingleNode("Nodes");
foreach (XmlNode node in xmlNodes)
{
XmlElement mNode = (XmlElement)node;
XmlPos.Add(mNode.GetAttribute("id"), mNode.GetAttribute("pos"));
XmlName.Add(mNode.GetAttribute("id"), mNode.GetAttribute("name"));
}
}