xml

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>
}

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值