• unity read xml


    
    

    /*

    编写:围城(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

  • 相关阅读:
    ffmpeg
    HDU 1031 Design T-Shirt
    HDU 1029 Ignatius and the Princess IV
    HDU 1022 Train Problem I
    HDU 1017 A Mathematical Curiosity
    HDU 1015 Safecracker
    HDU 1002 A + B Problem II
    HDU 1070 Milk
    高精度算法(一)
    codeblocks 使用心得
  • 原文地址:https://www.cnblogs.com/solq/p/2494146.html
Copyright © 2020-2023  润新知