コード例 #1
0
ファイル: XmlReaderBase.cs プロジェクト: GeorgeLiuXin/RPGdemo
        public void AddXml(XmlDataList data)
        {
#if UNITY_EDITOR
            if (File.Exists(m_XmlPathInEditor))
            {
                // xml文档实例
                XmlDocument xmlDoc = new XmlDocument();
                xmlDoc.Load(m_XmlPathInEditor);
                // 获取根节点
                XmlElement root = xmlDoc.SelectSingleNode(sRoot) as XmlElement;
                if (root == null)
                {
                    return;
                }

                if (data.iIndex == 0)
                {
                    return;
                }

                if (ContainsNode(root, sPreName + data.iIndex.ToString()))
                {
                    return;
                }

                //创建整个表现节点
                XmlElement curParentElm = xmlDoc.CreateElement(sPreName + data.iIndex.ToString());
                curParentElm.SetAttribute(iIndex, data.iIndex.ToString());
                curParentElm.SetAttribute(sDes, data.sDescribe);

                foreach (XmlClassData _class in data)
                {
                    //创建单个表现类型
                    XmlElement elm = xmlDoc.CreateElement(_class.sLogicName);
                    foreach (XmlParamItem _property in _class)
                    {
                        XmlElement elmProperty = xmlDoc.CreateElement(_property.sName);
                        elmProperty.SetAttribute("Type", _property.sType);
                        elmProperty.InnerText = GetPropertyValue(_property);
                        elm.AppendChild(elmProperty);
                    }
                    curParentElm.AppendChild(elm);
                }
                root.AppendChild(curParentElm);

                xmlDoc.Save(m_XmlPathInEditor);
            }
#endif
        }
コード例 #2
0
ファイル: XmlReaderBase.cs プロジェクト: GeorgeLiuXin/RPGdemo
        public void ReadXml(ref Dictionary <int, XmlDataList> dict)
        {
#if UNITY_EDITOR
            if (File.Exists(m_XmlPathInEditor))
            {
                XmlDocument xmlDoc = new XmlDocument();
                xmlDoc = new XmlDocument();
                xmlDoc.Load(m_XmlPathInEditor);
                XmlElement root = xmlDoc.SelectSingleNode(sRoot) as XmlElement;
                if (root == null)
                {
                    return;
                }

                foreach (XmlElement xml_data in root)
                {
                    if (xml_data == null)
                    {
                        continue;
                    }

                    XmlDataList _data = new XmlDataList();
                    _data.iIndex    = Convert.ToInt32(xml_data.GetAttribute(iIndex));
                    _data.sDescribe = xml_data.GetAttribute(sDes);

                    foreach (XmlElement xml_class in xml_data)
                    {
                        XmlClassData _class = new XmlClassData();
                        _class.sLogicName = xml_class.LocalName;

                        foreach (XmlElement xml_property in xml_class)
                        {
                            XmlParamItem _property = new XmlParamItem();
                            _property.sName  = xml_property.LocalName;
                            _property.sType  = xml_property.GetAttribute("Type");
                            _property.sValue = xml_property.InnerText;

                            _class.Add(_property);
                        }

                        _data.Add(_class);
                    }

                    if (dict.ContainsKey(_data.iIndex))
                    {
                        dict.Remove(_data.iIndex);
                    }
                    dict.Add(_data.iIndex, _data);
                }
            }
#else
            string strFileCon = ResourcesProxy.LoadTextString(m_XmlFilePath);
            if (string.IsNullOrEmpty(strFileCon))
            {
                return;
            }

            XmlDocument xmlDoc = new XmlDocument();
            xmlDoc = new XmlDocument();
            try
            {
                byte[]       buffer = System.Text.Encoding.UTF8.GetBytes(strFileCon);
                MemoryStream ms     = new MemoryStream(buffer);
                xmlDoc.Load(ms);
            }
            catch (XmlException e)
            {
                Log.Debug("LoadDefine error!");
                Log.Debug("line : " + e.LineNumber + " pos : " + e.LinePosition);
                Log.Debug("reason : " + e.Message);
            }

            XmlElement root = xmlDoc.SelectSingleNode(sRoot) as XmlElement;
            if (root == null)
            {
                return;
            }

            foreach (XmlElement xml_data in root)
            {
                if (xml_data == null)
                {
                    continue;
                }

                XmlDataList _data = new XmlDataList();
                _data.iIndex    = Convert.ToInt32(xml_data.GetAttribute(iIndex));
                _data.sDescribe = xml_data.GetAttribute(sDes);

                foreach (XmlElement xml_class in xml_data)
                {
                    XmlClassData _class = new XmlClassData();
                    _class.sLogicName = xml_class.LocalName;

                    foreach (XmlElement xml_property in xml_class)
                    {
                        XmlParamItem _property = new XmlParamItem();
                        _property.sName  = xml_property.LocalName;
                        _property.sType  = xml_property.GetAttribute("Type");
                        _property.sValue = xml_property.InnerText;

                        _class.Add(_property);
                    }

                    _data.Add(_class);
                }

                if (dict.ContainsKey(_data.iIndex))
                {
                    dict.Remove(_data.iIndex);
                }
                dict.Add(_data.iIndex, _data);
            }
#endif
        }