zoukankan      html  css  js  c++  java
  • unity 加载读取外部XML

    cfg.xml

    <rootNode>
        <category name="网站">
            <item name="mainPage">www.4463.com</item>
        </category >
    </rootNode>
    testReadXml.cs
    using UnityEngine;
    using System.Collections;
    using System.Xml;
    
    public class testReadXml : MonoBehaviour {
        public string xmlURL;//http://192.168.1.106/app/cfg.xml
    
        void Start () {
            StartCoroutine (getXML());
        }
    
        IEnumerator getXML(){
            WWW www = new WWW (xmlURL);
            string progress;
            while(!www.isDone){
                progress=(((int)(www.progress * 100)) % 100) + "%";
                Debug.Log (progress);
                yield return 1;
            }
            if(www.error!=null){
                Debug.Log ("loading error:"+www.url);
            }else{
                progress="100%";
                Debug.Log (progress);
                //enter complete code
                Debug.Log(www.text);
                parseXML(www.text);
            }
        }
    
        private void parseXML(string xmlText){
            XmlDocument xmlDoc=new XmlDocument();
            xmlDoc.LoadXml(xmlText);
            XmlNodeList nodeList=xmlDoc.SelectSingleNode("rootNode").ChildNodes;
            for(int i=0;i<nodeList.Count;i++){
                XmlElement category=nodeList[i] as XmlElement;
                Debug.Log (category.GetAttribute("name"));//output: 网站
                Debug.Log (category.InnerXml);//output: <item name="mainPage">www.4463.com</item>
                for(int j=0;j<category.ChildNodes.Count;j++){
                    XmlElement item=category.ChildNodes[j] as XmlElement;
                    Debug.Log (item.GetAttribute("name"));//output: mainPage
                    Debug.Log (item.InnerXml);//output: www.4463.com
                    Debug.Log (item.InnerText);//output: www.4463.com
                }
            }
    
        }
    
    }
  • 相关阅读:
    laravel5.2 开发中打印sql语句
    centos 安装 vsftpd
    linux 安装 DenyHosts 防止密码被暴力破解
    linux nginx 安装防火墙ngx_lua_waf
    mysql 下载资源地址
    微信公众号 access_token 没有过期 却失效
    centos 安装 composer
    五十个小技巧提高PHP执行效率
    yii 使用DB实现rbac 权限控制
    git 的使用
  • 原文地址:https://www.cnblogs.com/kingBook/p/6483011.html
Copyright © 2011-2022 走看看