unity基础开发----常用代码Unity中解析XML

C#代码
using UnityEngine;
using System.Collections;
using System.Xml;

public class NewBehaviourScript : MonoBehaviour {

	// Use this for initialization
	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("equipCondition") == "2")
                {
                    print("+++++++++++++++++++++++++++++++++++++++++++++++++");
                    break;
                }
            }
        }        

       
	}
	
	// Update is called once per frame
	void Update () {
	
	}
    //
  
}

xml代码

<?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="2" 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>
备用: http://blog.csdn.net/daijinghui512/article/details/20929185

你可能感兴趣的:(unity基础开发----常用代码Unity中解析XML)