using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using System.Xml;
using System.IO;
public class XmlManager:BaseManager
{
public XmlManager(GameManager gameManager):base(gameManager)
{
}
private string id1;
private string name1;
private string year1;
private string id2;
private string name2;
private string year2;
public void ParseXml()
{
string filePath = Application.dataPath + "/Resources/Xml/item.xml";
if (File.Exists(filePath))
{
XmlDocument xmlDoc = new XmlDocument();
xmlDoc.Load(filePath);
XmlNodeList node = xmlDoc.SelectSingleNode("item").ChildNodes;
foreach (XmlElement ele in node)
{
Debug.Log(ele.Name);
if (ele.Name == "item1")
{
foreach (XmlElement i1 in ele.ChildNodes)
{
Debug.Log(i1.Name);
if (i1.Name == "id")
{
id1 = i1.InnerText;
}
if (i1.Name == "name")
{
name1 = i1.InnerText;
}
if (i1.Name == "year")
{
year1 = i1.InnerText;
}
}
}
if (ele.Name == "item2")
{
foreach (XmlElement i2 in ele.ChildNodes)
{
Debug.Log(i2.Name);
if (i2.Name == "id")
{
id2 = i2.InnerText;
}
if (i2.Name == "name")
{
name2 = i2.InnerText;
}
if (i2.Name == "year")
{
year2 = i2.InnerText;
}
}
}
}
}
Debug.Log("id1: " + id1);
Debug.Log("name1: " + name1);
Debug.Log("year1: " + year1);
Debug.Log("id2: " + id2);
Debug.Log("name2: " + name2);
Debug.Log("year2: " + year2);
}
}
转载请注明原文地址:https://ipadbbs.8miu.com/read-54624.html