Unity 读取xml 文件

前端之家收集整理的这篇文章主要介绍了Unity 读取xml 文件前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。

原址:http://www.cnblogs.com/solq/archive/2012/05/10/2494146.html

/*

编写:围城(solq)

日期:2012-5-8

blog:http://www.cnblogs.com/solq/

*/


using UnityEngine;
using System.Collections;
using System.Xml;
public class ReadXml : MonoBehavIoUr {

    void Start () {
        print(Application.dataPath);
        string url = Application.dataPath + "/test.xml";

        XmlDocument xmldoc = new XmlDocument();

        xmldoc.Load(url);

         //读取方式一
        XmlNode root = xmldoc.SelectSingleNode("datas");
        if (root != null)
        {           
            XmlNodeList nodelist = root.ChildNodes;
            foreach (XmlNode node in nodelist)
            {
                XmlElement xmlelement = (XmlElement)node;
                if (xmlelement.GetAttribute("skillID") == "1006")
                {
                    print("+++++++++++++++++++++++++++++++++++++++++++++++++");
                    break;
                }
            }

        }

        //方式二。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。

        XmlElement n = (XmlElement)xmldoc.SelectSingleNode("/datas/data[@skillID='1006']"); //叫什么语法忘记了。。。
        if (n != null)
        {
            print("+++++++++++++++++++++++++++++++++++++++++++++++++");
            print(n.GetAttribute("skillID"));
        }  

    }

}

xml file

<?xml version="1.0" encoding="UTF-8"?>
<datas>
 <data skillID="1001" skillType="1" skillName="一击必杀" equipCondition="0" learnCondition="0" learnMoney="0" skillLevel="1" skillDamage="0" angerCost="0" conjureTime="0" coolDownTime="0" scopeType="2" scope="4" effectID="0" effectRate="0" hitFlyDis="2" />
 <data skillID="1002" skillType="1" skillName="一击必杀" equipCondition="0" learnCondition="0" learnMoney="0" skillLevel="1" skillDamage="0" angerCost="0" conjureTime="0" coolDownTime="0" scopeType="2" scope="4" effectID="0" effectRate="0" hitFlyDis="2" />
 <data skillID="1003" skillType="1" skillName="一击必杀" equipCondition="0" learnCondition="0" learnMoney="0" skillLevel="1" skillDamage="0" angerCost="0" conjureTime="0" coolDownTime="0" scopeType="2" scope="4" effectID="0" effectRate="0" hitFlyDis="2" />
 <data skillID="1004" skillType="1" skillName="一击必杀" equipCondition="0" learnCondition="0" learnMoney="0" skillLevel="1" skillDamage="0" angerCost="0" conjureTime="0" coolDownTime="0" scopeType="2" scope="4" effectID="0" effectRate="0" hitFlyDis="2" />
 <data skillID="1005" skillType="1" skillName="一击必杀" equipCondition="0" learnCondition="0" learnMoney="0" skillLevel="1" skillDamage="0" angerCost="0" conjureTime="0" coolDownTime="0" scopeType="2" scope="4" effectID="0" effectRate="0" hitFlyDis="2" />
 <data skillID="1006" skillType="1" skillName="一击必杀" equipCondition="0" learnCondition="0" learnMoney="0" skillLevel="1" skillDamage="0" angerCost="0" conjureTime="0" coolDownTime="0" scopeType="2" scope="4" effectID="0" effectRate="0" hitFlyDis="2" />
 <data skillID="1007" skillType="1" skillName="一击必杀" equipCondition="0" learnCondition="0" learnMoney="0" skillLevel="1" skillDamage="0" angerCost="0" conjureTime="0" coolDownTime="0" scopeType="2" scope="4" effectID="0" effectRate="0" hitFlyDis="2" />
</datas>

选择xml 模板语法

http://hi.baidu.com/yang0000meng/blog/item/bb8c7a72547944168601b078.html

哦想起来了,,叫 xpath

http://www.cnblogs.com/cstded/archive/2007/02/16/651685.html

转自:http://blog.csdn.net/miaoweiye/article/details/8243905?reload

猜你在找的XML相关文章