using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using System.Xml;
public class MyXML : MonoBehaviour
{
void Start()
{
XmlDocument d = new XmlDocument();
d.Load(Application.dataPath + "/myXml.xml");
XmlElement root = d.DocumentElement;
//XmlNodeList list = root.ChildNodes;
//XmlElement node = (XmlElement)list[0];
//Debug.Log(node["task2"].GetAttribute("msg"));// 子节点属性值 = 父节点标签元素[子节点标签元素].GetAttribute(子节点属性)
XmlNodeList list = root.ChildNodes;
for (int i = 0; i < list.Count; i++)
{
XmlElement node = (XmlElement)list[i];//Leval
Debug.Log(node.GetAttribute("leval") + " " + node.GetAttribute("tip"));
XmlNodeList childList = node.ChildNodes;//task----4
for (int j = 0; j < childList.Count; j++)
{
XmlElement chilenode = (XmlElement)childList[j];
string name = chilenode.GetAttribute("name");//属性值 = 标签元素.GetAttribute(属性名)
string msg = chilenode.GetAttribute("msg");
string money = chilenode.GetAttribute("money");
Debug.Log(name + " " + msg + " " + money);
}
}
}
// <Task>
// <Leval1 leval = '1' tip='新手村'>
// <task1 name = '打狼任务' msg='去后山帮我打五只狼皮回来' money='10000' x='100.33' y='123.33' z='34.32' />
// <task2 name = '取水' msg='菜地需要一些水' money='5000' x='50.33' y='13.33' z='4.32' />
// <task3 name = '收取虾壳' msg='我需要一些虾壳来做项链,你去帮我收集一些来' money='13000' x='550.33' y='134.33' z='42.32' />
// <task4 name = '伐木' msg='近来房子坏了,帮我去后山确一些木头回来' money='5000' x='100.33' y='123.33' z='43.32'/>
// </Leval1>
// <Leval2 leval = '10' tip='副本任务'>
// <task5 name = '龙呤' msg='最近听说东南方出现了一只青龙,要是能得到它的龙角就好了' money='50000' x='100.33' y='123.33' z='34.32' />
// <task6 name = '虎魂铠甲' msg='在遥远的北方,出现了一只全身金黄色的白虎,最近刚好缺少铠甲的材料' money='5000' x='50.33' y='13.33' z='4.32' />
// <task7 name = '朱雀之心' msg='火炎谷中,常年有妖兽出没,不知道能不能找到朱雀之心' money='13000' x='550.33' y='134.33' z='42.32' />
// <task8 name = '玄武精魂' msg='南方有一落天瀑布,传说下面有一种神物,发能取其精魂,能长生不老' money='5000' x='100.33' y='123.33' z='43.32' />
// </Leval2>
//</Task>
}