⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 xmlparser.cpp

📁 游戏框架
💻 CPP
字号:
// ***************************************************************
//  XMLParser   version:  1.0
//  -------------------------------------------------------------
//	File Name:	XMLParser.cpp
//	Created:	2007/07/18
//	Modified:	2007/07/18   14:56
//	Author:		William.Liang
//  Msn:		lwq49@msn.com
//  Email:		lwq49@21cn.com, lwq49@msn.com
//	Description:
//
//	Purpose:	
//  -------------------------------------------------------------
//  license:
//
//  The contents of this file are subject to the Mozilla Public
//  License Version 1.1 (the "License"); you may not use this file
//  except in compliance with the License. You may obtain a copy
//  of the License at http://www.mozilla.org/MPL/ Software dis-
//  tributed under the License is distributed on an "AS IS" 
//  basis, WITHOUT WARRANTY OF ANY KIND, either express or im-
//  plied. See the License for the specific language governing
//  rights and limitations under the License.
//
//  The Initial Developer of the Original Code is William.Liang .
//  Copyright (C) 2007 - All Rights Reserved.
// ***************************************************************
#include "StdAfx.h"
#include ".\XmlParser.h"
#include ".\GameLayouter.h"

//************************************
// <p>Descript:    CXMLParser</p>
//************************************
CXMLParser::CXMLParser()
{
	m_pGameLayouterSink		= NULL;
}

//************************************
// <p>Descript:    ~CXMLParser</p>
//************************************
CXMLParser::~CXMLParser(void)
{
}

//************************************
// <p>Descript:    载入XML</p>
// <p>Parameters:  </p>
// <p>    LPCTSTR lpFileName</p>
// <p>    bool bIsAsync</p>
//
// <p>Returns:   bool</p>
//************************************
bool CXMLParser::LoadXmlFromFile(LPCTSTR lpFileName, bool bIsAsync)
{
	m_bIsAsync	= bIsAsync;
	return m_XmlDocument.LoadFile(lpFileName);
}

//************************************
// <p>Descript:    XML分析</p>
// <p>Parameters:  </p>
// <p>    TiXmlNode * pNode - 当前分解结点</p>
//
// <p>Returns:   bool</p>
//************************************
bool CXMLParser::Parse(TiXmlNode* pNode)
{
	if(m_XmlDocument.Error()) return false;

	//异步操作
	if(m_bIsAsync){
	}
	else{
		TiXmlElement*			pItem;
		if(pNode==NULL)
			pNode = m_XmlDocument.FirstChild();
		else
			pNode = pNode->FirstChild();

		//枚举该结点下所有同层结点
		while(pNode){
			if(pNode->Type()==TiXmlNode::ELEMENT){
				pItem = pNode->ToElement();

				if(m_pGameLayouterSink){
					TiXmlElement*	pParentNode		= pNode->Parent()->ToElement();
					_CString			szParentName	= "";
					if(pParentNode)
						szParentName	= pParentNode->Value();
					/*
					try{
						 
					}
					catch(...){
					}
					*/
					_CString			szNodeName		= pItem->Value();
					_CStringList*	pStringList		= NULL;
					TiXmlAttribute*	pAttributes		= pItem->FirstAttribute();

					if(pAttributes){
						pStringList = new _CStringList();

						//枚举所有属性
						while(pAttributes){
							char*		pAttributName;
							char*		pAttributValue;
							pAttributName	= (char *)pAttributes->Name();
							pAttributValue	= (char *)pAttributes->Value();

							//放入一个属性链表
							pStringList->Push((LPCTSTR)pAttributValue, (LPCTSTR)pAttributName);
							pAttributes = pAttributes->Next();
						}
					}

					//转交接口处理
					m_pGameLayouterSink->Processer(szNodeName, szParentName, pStringList);
					//释放属性链表
					SafeDelete(pStringList);
				}

				if(!pNode->NoChildren())
					Parse(pNode);
			}
			pNode = pNode->NextSibling();
		}
	}

	return true;
}

//************************************
// <p>Descript:    设置布局回调接口</p>
// <p>Parameters:  </p>
// <p>    IGameLayouterSink * pGameLayouterSink</p>
//
// <p>Returns:   void</p>
//************************************
void CXMLParser::SetLayouterSink(IGameLayouterSink* pGameLayouterSink){
	m_pGameLayouterSink	= pGameLayouterSink;
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -