Manager Of Managers(十)XmlManager

//==========================
// - FileName:      XmlManager.cs         
// - Created:       true.	
// - CreateTime:    2020/06/30 22:16:00	
// - Email:         1670328571@qq.com		
// - Region:        China WUHAN	
// - Description:   Xml 管理者
//==========================
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using System.Xml;     //xml操作
using System.IO;     //file操作

public class XmlManager:BaseManager
{
    //public GameManager gameManager;
    public XmlManager(GameManager gameManager):base(gameManager)
    {
        //gameManager = GameManager.Instance;
        //ParseXml();
    }
    
    private string id1;
    private string name1;
    private string year1;
    private string id2;
    private string name2;
    private string year2;
    //解析xml
    public void ParseXml()
    {
        //也可以前面加上@,区别就是有@的话,双引号里面的内容不转义,比如" \" "
        //string filePath = Application.dataPath+@"/Resources/item.xml";
        string filePath = Application.dataPath + "/Resources/Xml/item.xml";
        if (File.Exists(filePath))
        {
            XmlDocument xmlDoc = new XmlDocument();
            xmlDoc.Load(filePath);
            XmlNodeList node = xmlDoc.SelectSingleNode("item").ChildNodes;
            //遍历节点
            foreach (XmlElement ele in node)
            {
                //item下面的节点
                Debug.Log(ele.Name);

                if (ele.Name == "item1")
                {
                    //first item1
                    foreach (XmlElement i1 in ele.ChildNodes)
                    {
                        Debug.Log(i1.Name);
                        if (i1.Name == "id")
                        {
                            id1 = i1.InnerText;
                        }
                        if (i1.Name == "name")
                        {
                            name1 = i1.InnerText;
                        }
                        if (i1.Name == "year")
                        {
                            year1 = i1.InnerText;
                        }
                    }
                }
                if (ele.Name == "item2")
                {
                    //first item1
                    foreach (XmlElement i2 in ele.ChildNodes)
                    {
                        Debug.Log(i2.Name);
                        if (i2.Name == "id")
                        {
                            id2 = i2.InnerText;
                        }
                        if (i2.Name == "name")
                        {
                            name2 = i2.InnerText;
                        }
                        if (i2.Name == "year")
                        {
                            year2 = i2.InnerText;
                        }
                    }
                }

            }
        }
        Debug.Log("id1:  " + id1);
        Debug.Log("name1:  " + name1);
        Debug.Log("year1:  " + year1);
        Debug.Log("id2:  " + id2);
        Debug.Log("name2:  " + name2);
        Debug.Log("year2:  " + year2);
    }



}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值