Beispiel #1
0
bool dumpXML(string& fname)
{
    try {
        TiXmlDocument* doc = new TiXmlDocument (fname.c_str());
        doc->LoadFile ();
        TiXmlElement* root = doc->RootElement ();
        
        cout << root->Value () << endl;

        TiXmlElement* version = root->FirstChildElement ();
        TiXmlAttribute* atti_major = version->FirstAttribute ();
        TiXmlAttribute* atti_minor = version->LastAttribute ();

        TiXmlElement* file = version->FirstChildElement ();
        TiXmlAttribute* atti_size = file->FirstAttribute ();
        TiXmlAttribute* atti_date = file->LastAttribute ();

        cout << version->FirstChild ()->Value() << endl;
        cout << atti_major->Name () << ": " << atti_major->Value () << ", " <<
        atti_minor->Name () << ": " << atti_minor->Value () << endl;
        cout << file->FirstChild ()->Value() << endl;
        cout << atti_size->Name () << ": " << atti_size->Value () << ", " << \
        atti_date->Name () << ": " << atti_date->Value () << endl;

    }
    catch (string& e) {
        return (false);
    }

    return true;
}
Beispiel #2
0
void CharacterLoader::Load(TiXmlDocument& doc)
{
	TiXmlElement* root = doc.FirstChildElement("Body");
	root = root->FirstChildElement("Character");
	while (root)
	{
		TiXmlAttribute* attribute = root->FirstAttribute();
		std::string str = attribute->Name();
		if (str == "name")
		{
			std::string characterName = attribute->Value();
			std::string fileName;
			int x1 = -1, x2 = -1, y1 = -1, y2 = -1;
			TiXmlElement* element = root->FirstChildElement("a");
			
			while (element)
			{
				TiXmlAttribute* attrib = element->FirstAttribute();
				while (attrib)
				{
					std::string name = attrib->Name();
					std::string value = attrib->Value();
					addValue(characterName, name, value);

					attrib = attrib->Next();
				}
				element = element->NextSiblingElement("a");
			}

		}

		root = root->NextSiblingElement("Character");
	}
}
Beispiel #3
0
void ImageLoader::Load(TiXmlDocument& doc)
{
	TiXmlElement* root = doc.FirstChildElement("Body");
	root = root->FirstChildElement("Image");
	while (root)
	{
		TiXmlAttribute* attribute = root->FirstAttribute();
		std::string str = attribute->Name();
		if (str == "name")
		{
			std::string imageName = attribute->Value();
			std::string fileName;
			int x1 = -1, x2 = -1, y1 = -1, y2 = -1;
			TiXmlElement* element = root->FirstChildElement("a");
			if (element)
			{
				if (element->Attribute("file"))
				{
					fileName = element->Attribute("file");
				}
			}

			element = root->FirstChildElement("rect");

			while (element)
			{

				TiXmlAttribute* attrib = element->FirstAttribute();
				while (attrib)
				{
					std::string name = attrib->Name();
					if (name == "x1")
					{
						x1 = attrib->IntValue();
					}
					else if (name == "x2")
					{
						x2 = attrib->IntValue();
					}
					else if (name == "y1")
					{
						y1 = attrib->IntValue();
					}
					else if (name == "y2")
					{
						y2 = attrib->IntValue();
					}

					attrib = attrib->Next();
				}
				element = element->NextSiblingElement("rect");
			}

			internalCreate(imageName, fileName, x1, y1, x2, y2);
		}

		root = root->NextSiblingElement("Image");
	}
}
bool wxsItemResData::RebuildXrcFile()
{
    // First - opening file
    TiXmlDocument Doc;
    TiXmlElement* Resources = nullptr;
    TiXmlElement* Object = nullptr;

    if ( TinyXML::LoadDocument(m_XrcFileName,&Doc) )
    {
        Resources = Doc.FirstChildElement("resource");
    }

    if ( !Resources )
    {
        Doc.Clear();
        Doc.InsertEndChild(TiXmlDeclaration("1.0","utf-8",""));
        Resources = Doc.InsertEndChild(TiXmlElement("resource"))->ToElement();
        Resources->SetAttribute("xmlns","http://www.wxwidgets.org/wxxrc");
    }

    // Searching for object representing this resource
    for ( Object = Resources->FirstChildElement("object"); Object; Object = Object->NextSiblingElement("object") )
    {
        if ( cbC2U(Object->Attribute("name")) == m_ClassName )
        {
            Object->Clear();
            while ( Object->FirstAttribute() )
            {
                Object->RemoveAttribute(Object->FirstAttribute()->Name());
            }
            break;
        }
    }

    if ( !Object )
    {
        Object = Resources->InsertEndChild(TiXmlElement("object"))->ToElement();
    }

    // The only things left are: to dump item into object ...
    m_RootItem->XmlWrite(Object,true,false);
    Object->SetAttribute("name",cbU2C(m_ClassName));
    for ( int i=0; i<GetToolsCount(); i++ )
    {
        TiXmlElement* ToolElement = Object->InsertEndChild(TiXmlElement("object"))->ToElement();
        m_Tools[i]->XmlWrite(ToolElement,true,false);
    }

    // ... and save back the file
    return TinyXML::SaveDocument(m_XrcFileName,&Doc);
}
void MeshCompiler::CompileAnimations( TiXmlElement* Arm )
{
	// Get named animations from the keyframes
	for( TiXmlElement* Keyf = Arm->FirstChildElement( "anim" ); Keyf; Keyf = Keyf->NextSiblingElement( "anim" ) )
	{
		Animation Animation;

		// Get starting frame and name (patch up lengths later)
		TiXmlAttribute* KeyfAttr = Keyf->FirstAttribute();
		Animation.m_StartFrame = (uint16)KeyfAttr->IntValue();

		KeyfAttr = KeyfAttr->Next();
		const char* pName = KeyfAttr->Value();
		CleanStrncpy( Animation.m_Name, pName, ANIM_NAME_LENGTH );
		Animation.m_HashedName = Animation.m_Name;

		m_Animations.PushBack( Animation );
		++m_Header.m_NumAnims;
	}
	for( int i = 0; i < ( m_Header.m_NumAnims - 1 ); ++i )
	{
		Animation& ThisAnim = m_Animations[ i ];
		Animation& NextAnim = m_Animations[ i + 1 ];
		ThisAnim.m_Length = NextAnim.m_StartFrame - ThisAnim.m_StartFrame;
	}
	// Patch up the last animation's length separately
	if( m_Header.m_NumAnims )
	{
		Animation& ThisAnim = m_Animations[ m_Header.m_NumAnims - 1 ];
		ThisAnim.m_Length = (uint16)( ( m_Header.m_NumFrames ) - ThisAnim.m_StartFrame );	// -1 because of added T-pose
	}
}
BaseModule * XmlConfigurationLoader::LoadModule(void * module){
	TiXmlElement * elem = (TiXmlElement * )module;
	TiXmlAttribute * attr = elem->FirstAttribute();
	if(attr == 0){
		return 0;
	}
	map<string, string> parameters_map;
	while(attr){
		
		parameters_map.insert(	pair<string,string>(
									string(attr->Name()),
									string(attr->Value())
								)		
							);
		attr = attr->Next();
	}

	BaseModule * loaded_module = mDl->LoadModuleFrom(parameters_map[string("src")]);
	if (loaded_module != 0){
		for (map<string, string>::iterator it = parameters_map.begin();
			it != parameters_map.end();
			it++){
			loaded_module->AddAttribute(it->first, it->second);
		}
	}
	return loaded_module;
}
Beispiel #7
0
/*!
*  /brief 修改指定节点的属性值。
*
*  /param XmlFile xml文件全路径。
*  /param strNodeName 指定的节点名。
*  /param AttMap 重新设定的属性值,这是一个map,前一个为属性名,后一个为属性值
*  /return 是否成功。true为成功,false表示失败。
*/
bool xml_ModifyNode_Attribute(TiXmlElement *pRootEle, std::string strNodeName,
        std::map<std::string, std::string> &AttMap)
{
    typedef std::pair<std::string, std::string> String_Pair;
    if (NULL == pRootEle) {
        return false;
    }

    TiXmlElement *pNode = NULL;
    xml_GetNodePointerByName(pRootEle, strNodeName, pNode);
    if (NULL != pNode) {
        TiXmlAttribute* pAttr = NULL;
        std::string strAttName;
        for (pAttr = pNode->FirstAttribute(); pAttr; pAttr = pAttr->Next()) {
            strAttName = pAttr->Name();
            std::map<std::string, std::string>::iterator iter;
            for (iter = AttMap.begin(); iter != AttMap.end(); iter++) {
                if (strAttName == iter->first) {
                    pAttr->SetValue(iter->second);
                }
            }
        }
        return true;
    } else {
        return false;
    }
}
Beispiel #8
0
void CALLBACK CUICommandHistory::UIModify(TiXmlNode* pNode)
{
	TiXmlElement* pElement = pNode->ToElement();
	CStringA strName = pElement->Attribute("myname");
	pElement->RemoveAttribute("myname");
	if(strName.IsEmpty())
		return;

	CPaintManagerUI* pManager = g_pMainFrame->GetActiveUIView()->GetPaintManager();
	CControlUI* pControl = pManager->FindControl(StringConvertor::Utf8ToWide(strName));
	TiXmlAttribute* pAttrib = pElement->FirstAttribute();
	if(pControl == NULL)
		return;

	while(pAttrib)
	{
		if(strcmp(pAttrib->Name(), "name") == 0)
		{
			pManager->ReapObjects(pControl);
			g_pClassView->RenameUITreeItem(pControl, StringConvertor::Utf8ToWide(pAttrib->Value()));
			pControl->SetAttribute(StringConvertor::Utf8ToWide(pAttrib->Name())
				, StringConvertor::Utf8ToWide(pAttrib->Value()));
			pManager->InitControls(pControl);
		}
		else
			pControl->SetAttribute(StringConvertor::Utf8ToWide(pAttrib->Name())
				, StringConvertor::Utf8ToWide(pAttrib->Value()));

		pAttrib = pAttrib->Next();
	}
	CControlUI* pParent = pControl->GetParent();
	if(pParent == NULL)
		pParent = pControl;
	pParent->SetPos(pParent->GetPos());
}
void HelloWorld::parseTinyXmlFile()
{
	try
	{
		char filePath[1024]= {'\0'};
		memset(filePath,0,sizeof(filePath));
		strcat(filePath,CCFileUtils::sharedFileUtils()->getWriteablePath().c_str());
		strcat(filePath,"CreatedTinyXml.xml");

		//创建一个XML的文档对象。
		TiXmlDocument *myDocument = new TiXmlDocument(filePath);
		myDocument->LoadFile();
		//获得根元素,即Persons。
		TiXmlElement *RootElement = myDocument->RootElement();
		//输出根元素名称,即输出Persons。
		CCLOG(RootElement->Value());
		//获得第一个Person节点。
		TiXmlElement *FirstPerson = RootElement->FirstChildElement();
		//获得第一个Person的name节点和age节点和ID属性。
		TiXmlElement *NameElement = FirstPerson->FirstChildElement();
		TiXmlElement *AgeElement = NameElement->NextSiblingElement();
		TiXmlAttribute *IDAttribute = FirstPerson->FirstAttribute();
		//输出第一个Person的name内容,即周星星;age内容,即;ID属性,即。

		CCLOG(NameElement->FirstChild()->Value());
		CCLOG(AgeElement->FirstChild()->Value());
		CCLOG(IDAttribute->Value());
	}
	catch (string& e)
	{
		return ;
	}
	return ;
}
Beispiel #10
0
/**
* 从xml文件中读取“键-值”对 load "key-value" from xml file
* @param filename 读取的xml文件,必须是按照规定的格式
* @return 布尔值 读取成功与否
*/
bool Properties::loadFromXML(const string filename)
{
	TiXmlDocument doc(filename.c_str());
	bool loadOkay = doc.LoadFile();//以utf-8格式读取xml文件
	if (!loadOkay)
	{
		return false;
	}
	TiXmlNode *node = doc.FirstChild("properties");
        #ifdef DEBUG_PROPERTIES_H
	node->Print(stdout, 1);
	cout << endl;
        #endif
	TiXmlElement* propertiesElement = node->ToElement();
	for(TiXmlElement *it = propertiesElement->FirstChildElement("entry")
		; it!=NULL ;
		it = it->NextSiblingElement("entry")
		)
	{
		TiXmlAttribute *att = it->FirstAttribute();
		this->setProperty(att->Value(), it->GetText());
		#ifdef DEBUG_PROPERTIES_H
		cout << "[" << att->Name() << ":" << att->Value() << "->" << it->GetText() << "]" << endl;
                #endif
	}
	return true;
}
void xmlLeafLoad::DecodeLeaf( TiXmlElement* root )
{
	//извлечь данные о листве

	//извлечение информации из узла XML
	TiXmlNode* node = root->FirstChild( m_LeafNames.m_sLeaf.c_str() );

	if ( node )
	{
		TiXmlElement* pLeaf = node->ToElement();

		//извлечь имя элемента
		const char *_name = pLeaf->Value();
		std::string _sElem( _name );

		//получить указатель на первый атрибут элемента
		TiXmlAttribute* _attr = pLeaf->FirstAttribute();

		//извлечь данные о текстурах
		DecodeTextures( pLeaf );

		//извлечь данные о влиянии ветра
		DecodeWind( pLeaf );

		//декодировать данные LOD'ов
		DecodeLODs( pLeaf );
	}
}
Beispiel #12
0
bool ReadXmlFile(std::string& szFileName)
{//读取Xml文件,并遍历
	try
	{
		std::string fullPath = GetAppPath();
		fullPath += "\\";
		fullPath += szFileName;
		//创建一个XML的文档对象。
		TiXmlDocument *myDocument = new TiXmlDocument(fullPath.c_str());
		myDocument->LoadFile();
		//获得根元素,即Persons。
		TiXmlElement *RootElement = myDocument->RootElement();
		//输出根元素名称,即输出Persons。
		std::cout << RootElement->Value() << std::endl;
		//获得第一个Person节点。
		TiXmlElement *FirstPerson = RootElement->FirstChildElement();
		//获得第一个Person的name节点和age节点和ID属性。
		TiXmlElement *NameElement = FirstPerson->FirstChildElement();
		TiXmlElement *AgeElement = NameElement->NextSiblingElement();
		TiXmlAttribute *IDAttribute = FirstPerson->FirstAttribute();
		//输出第一个Person的name内容,即周星星;age内容,即;ID属性,即。
		std::cout << NameElement->FirstChild()->Value() << std::endl;
		std::cout << AgeElement->FirstChild()->Value() << std::endl;
		std::cout << IDAttribute->Value()<< std::endl;
	}
	catch (std::string& e)
	{
		return false;
	}
	return true;
}
Beispiel #13
0
int main()  
{  
    //创建一个XML的文档对象。  
    TiXmlDocument *myDocument = new TiXmlDocument("test.xml");  
    myDocument->LoadFile();  
      
    //获得根元素,即Persons。  
    TiXmlElement *RootElement = myDocument->RootElement();  
  
    //输出根元素名称,即输出Persons。  
    cout << RootElement->Value() << endl;  
      
    //获得第一个Person节点。  
    TiXmlElement *FirstPerson = RootElement->FirstChildElement();  
    //输出接点名Person  
  
    cout << FirstPerson->Value() << endl;  
    //获得第一个Person的name节点和age节点和ID属性。  
    TiXmlElement *NameElement = FirstPerson->FirstChildElement();  
    TiXmlElement *AgeElement = NameElement->NextSiblingElement();  
    TiXmlElement *SexElement = AgeElement->NextSiblingElement();  
    TiXmlAttribute *IDAttribute = FirstPerson->FirstAttribute();  
      
    //输出第一个Person的name内容,即周星星;age内容,即20;ID属性,即1。  
    cout << NameElement->FirstChild()->Value() << endl;  
    cout << AgeElement->FirstChild()->Value() << endl;  
    cout << SexElement->FirstChild()->Value() << endl; 
    cout << IDAttribute->Value() << endl;  
  
    return 0;  
} 
void xmlLeafLoad::DecodeLODs( TiXmlElement* root )
{
	//декодировать данные LOD'ов

	//извлечение информации из узла XML
	TiXmlNode* node = root->FirstChild( m_LeafNames.m_sLODs.c_str() );

	if ( node )
	{
		TiXmlElement* pLODs = node->ToElement();

		//извлечь имя элемента
		const char *_name = pLODs->Value();
		std::string _sElem( _name );

		//получить указатель на первый атрибут элемента
		TiXmlAttribute* _attr = pLODs->FirstAttribute();

		//узнать количество LOD'ов
		DecodeAttrNumLods( _attr );

		//декодировать данные LOD'а
		DecodeLOD( pLODs );
	}
}
Beispiel #15
0
void CBaseScriptApp::LoadScriptSearchPathXml()
{
	CXmlConfig*		pXmlSearchDir	= LoadCfgFile( "etc/common/SearchDir.xml", "search_dir" );

	TiXmlNode*		pLoadPath = pXmlSearchDir->Get<TiXmlElement*>("load_path");

	const wchar_t* szRootPath = m_pRootPathMgr->GetRootPath();

	TiXmlNode* pNode = pLoadPath->FirstChild("path"); 
	while(pNode)
	{
		TiXmlElement* pElement = pNode->ToElement();
		if (pElement)
		{
			TiXmlAttribute* attribute = pElement->FirstAttribute();
			AddScriptLoadPath(attribute->Value(), pElement->GetText());
			wstring alias = utf8_to_utf16(attribute->Value());
			CPkgFile::AddLoadPath(alias.c_str(), szRootPath);
		}
		pNode = pNode->NextSibling();

	}
	
	SafeDelete(pXmlSearchDir);		
}
Beispiel #16
0
void readSchoolXml() {
    //using namespace std;
    const char * xmlFile = "conf/school.xml";
    TiXmlDocument doc;                              
    if (doc.LoadFile(xmlFile)) {
        doc.Print();
    } else {
        //cout << "can not parse xml conf/school.xml" << endl;
        return;
    }
    TiXmlElement* rootElement = doc.RootElement();  //School元素  
    TiXmlElement* classElement = rootElement->FirstChildElement();  // Class元素
    TiXmlElement* studentElement = classElement->FirstChildElement();  //Students  
    for (; studentElement != NULL; studentElement = studentElement->NextSiblingElement() ) {
        TiXmlAttribute* attributeOfStudent = studentElement->FirstAttribute();  //获得student的name属性  
        for (;attributeOfStudent != NULL; attributeOfStudent = attributeOfStudent->Next() ) {
            //cout << attributeOfStudent->Name() << " : " << attributeOfStudent->Value() << std::endl;       
        }                                 

        TiXmlElement* studentContactElement = studentElement->FirstChildElement();//获得student的第一个联系方式 
        for (; studentContactElement != NULL; studentContactElement = studentContactElement->NextSiblingElement() ) {
            //string contactType = studentContactElement->Value();
            //string contactValue = studentContactElement->GetText();
            //cout << contactType  << " : " << contactValue << std::endl;           
        }   
     
    } 
}
Beispiel #17
0
void 			BBWinConfig::LoadConfiguration(const string & fileName, const string & configNameSpace, bbwinconfig_t  & config) {
	string				configName(BBWIN_CONFIG_ROOT);

	EnterCriticalSection(&m_configCriticalSection); 
	m_path = fileName;
	m_doc = new TiXmlDocument(m_path.c_str());
	if (m_doc == NULL) 
		throw BBWinConfigException("can't allocare tinyxml instance");
	bool loadOkay = m_doc->LoadFile();
	if ( !loadOkay ) {
		LeaveCriticalSection(&m_configCriticalSection);
		throw BBWinConfigException(m_doc->ErrorDesc());
	}
	TiXmlElement *root = m_doc->FirstChildElement( "configuration" );
	if ( root ) {
		TiXmlNode * nameSpaceNode = root->FirstChild( configNameSpace.c_str() );
		if ( nameSpaceNode ) {
			TiXmlElement		* elem;
			for (elem = nameSpaceNode->FirstChildElement(); elem ; elem = elem->NextSiblingElement()) {
				bbwinconfig_attr_t		config_attr;
				if (elem->Type() == TiXmlNode::ELEMENT) {
					TiXmlAttribute 			* attr;
					
					for (attr = elem->FirstAttribute(); attr; attr = attr->Next()) {
						config_attr.insert(pair< string, string >(attr->Name(), attr->Value()));
					}
				}
				config.insert(pair < string, bbwinconfig_attr_t > (elem->Value(), config_attr));
			}
		}
	}
	delete m_doc;
	m_doc = NULL;
	LeaveCriticalSection(&m_configCriticalSection);
}
Beispiel #18
0
bool xml_QueryNode_Attribute(TiXmlElement *pRootEle, std::string strNodeName,
        std::string &attr_name, std::string &value)
{
    // 定义一个TiXmlDocument类指针
    typedef std::pair<std::string, std::string> String_Pair;
    if (NULL == pRootEle) {
        return false;
    }
    TiXmlElement *pNode = NULL;
    xml_GetNodePointerByName(pRootEle, strNodeName, pNode);
    if (NULL != pNode) {
        TiXmlAttribute* pAttr = NULL;
        for (pAttr = pNode->FirstAttribute(); pAttr; pAttr = pAttr->Next()) {
            if (attr_name == pAttr->Name()){
                value               = pAttr->Value();
                break;
            }
        }
        if (pAttr == NULL){
            return false;
        }
        return true;
    }
    return false;
}
Beispiel #19
0
    TiXmlElement* XMLDocument::ReplaceElement(TiXmlElement& target, const TiXmlElement& element)
    {
        TiXmlElement* pResult = NULL;
        TiXmlElement* existing = target.FirstChildElement(element.Value());
        if(existing && existing->FirstAttribute())
        {
            bool found = false;
            for(;existing && !found;existing=existing->NextSiblingElement())
            {
                bool match = true;
                const TiXmlAttribute* attr = element.FirstAttribute();
                for(;attr && match;attr=attr->Next())
                {
                    const char* val1 = existing->Attribute(attr->Name());
                    const char* val2 = attr->Value();
                    if(val1 == val2)
                        continue;
                    match &= val1 && val2 && strcmp(val1, val2) == 0;
                }
                if(match)
                    break;
            }
        }

        if(existing)
        {
            pResult = target.ReplaceChild(existing, element)->ToElement();
        }
        else
            pResult = target.InsertEndChild(element)->ToElement();

        return pResult;
    }
void xmlBranchLoad::DecodeBranch( TiXmlElement* root )
{
	//извлечь данные о стволе

	//извлечение информации из узла XML
	TiXmlNode* node = root->FirstChild( m_BranchNames.m_sBranch.c_str() );

	if ( node )
	{
		TiXmlElement* pBranch = node->ToElement();

		//извлечь имя элемента
		const char *_name = pBranch->Value();
		std::string _sElem( _name );

		//получить указатель на первый атрибут элемента
		TiXmlAttribute* _attr = pBranch->FirstAttribute();

		//декодировать параметр для альфа теста
		DecodeAttrAlfa( _attr );

		//извлечь данные о вершинах
		DecodeVertexs( pBranch );

		//извлечь данные о индексах
		DecodeStrips( pBranch );
	}
}
Beispiel #21
0
// static member function
HeeksObj* CAdaptive::ReadFromXMLElement(TiXmlElement* element)
{
	CAdaptive* new_object = new CAdaptive;

	std::list<TiXmlElement *> elements_to_remove;

	// read solid and sketch ids
	for(TiXmlElement* pElem = heeksCAD->FirstXMLChildElement( element ) ; pElem; pElem = pElem->NextSiblingElement())
	{
		std::string name(pElem->Value());
		if(name == "params"){
			new_object->m_params.ReadFromXMLElement(pElem);
			elements_to_remove.push_back(pElem);
		}
		else if(name == "solid"){
			for(TiXmlAttribute* a = pElem->FirstAttribute(); a; a = a->Next())
			{
				std::string name(a->Name());
				if(name == "id"){
					int id = a->IntValue();
					new_object->m_solids.push_back(id);
				}
			}
			elements_to_remove.push_back(pElem);
		}
		else if(name == "sketch"){
			for(TiXmlAttribute* a = pElem->FirstAttribute(); a; a = a->Next())
			{
				std::string name(a->Name());
				if(name == "id"){
					int id = a->IntValue();
					new_object->m_sketches.push_back(id);
				}
			}
			elements_to_remove.push_back(pElem);
		}
	}

	for (std::list<TiXmlElement*>::iterator itElem = elements_to_remove.begin(); itElem != elements_to_remove.end(); itElem++)
	{
		heeksCAD->RemoveXMLChild( element, *itElem);
	}

	new_object->ReadBaseXML(element);

	return new_object;
}
Beispiel #22
0
//TODO: Optimize this ..
void Sprite::init(TiXmlElement * pElement)
{
    if(pElement->ValueStr() != "sprite")
        return;

    TiXmlAttribute * pAtt = pElement->FirstAttribute();
    setFPS( pAtt->IntValue() );

    TiXmlElement * pChild = pElement->FirstChildElement();
    while(pChild != NULL)
    {
        if(pChild->ValueStr() != "surface")
            continue;

        std::string fileName = pChild->GetText();
        SDL_SurfacePtr pSurface = load_image(fileName);
        float zoom = 1.0f;
        float rot = 0.0f;
        float alpha = 1.0;

        TiXmlAttribute * pAttrib = pChild->FirstAttribute();
        if(pAttrib != NULL)
        {
            SDL_Rect rect = {-1,-1,-1,-1};
            while(pAttrib != NULL)
            {
                //std::cout << pAttrib->Name() << std::endl;
                if(pAttrib->Name() == std::string("x"))
                    rect.x = pAttrib->IntValue();
                else if(pAttrib->Name() == std::string("y"))
                    rect.y = pAttrib->IntValue();
                else if(pAttrib->Name() == std::string("w"))
                    rect.w = pAttrib->IntValue();
                else if(pAttrib->Name() == std::string("h"))
                    rect.h = pAttrib->IntValue();
                else if(pAttrib->Name() == std::string("rot"))
                    rot = pAttrib->DoubleValue();
                else if(pAttrib->Name() == std::string("zoom"))
                    zoom = pAttrib->DoubleValue();
                else if(pAttrib->Name() == std::string("alpha"))
                    alpha = pAttrib->DoubleValue();

                pAttrib = pAttrib->Next();
            }
            if( rect.x != -1 && rect.y != -1 && rect.w != -1 && rect.h != -1)
                pSurface = getSurface( pSurface.get(), rect );
            if( zoom != 1.0 || rot != 0.0f )
                pSurface = rotozoomSurface( pSurface.get(), rot, zoom, 1); //1 is for smoothing
            if( alpha != 1.0 )
            {
                int a = 255*alpha;
                SDL_SetAlpha( pSurface.get(), SDL_SRCALPHA|SDL_RLEACCEL, a);
            }
        }

        m_Sprites.push_back( new SDL_SurfacePtr(pSurface) );
        pChild = pChild->NextSiblingElement();
    }
}
Beispiel #23
0
bool SSHTablesConfig::Parse(string xmlFile) {
	TiXmlDocument *doc = new TiXmlDocument(xmlFile.c_str());
    if (doc->LoadFile()) {
		TiXmlElement *root = doc->RootElement();
		TiXmlElement *pack = root->FirstChildElement();
		while (pack != NULL) {
			if (string(pack->Value()) == "package-path") {
				packagePath = pack->GetText();
			}

			if (string(pack->Value()) == "tables") {
				TiXmlElement *t = pack->FirstChildElement();
				while (t != NULL) {
					if (string(t->Value()) == "table") {
						Table table;
						TiXmlElement *tb = t->FirstChildElement();
						while (tb != NULL) {	
							if (string(tb->Value()) == "name") {
								table.name = tb->GetText();
							}
							if (string(tb->Value()) == "schema") {
								table.schema = tb->GetText();
							}
							if (string(tb->Value()) == "objectName") {
								table.objectName = tb->GetText();
							}

							if (string(tb->Value()) == "columns") {
								TiXmlElement *col = tb->FirstChildElement();
								while (col != NULL) {
									if (string(col->Value()) == "column") {
										Column column = {"undefined", "undefined"};
										column.name = col->GetText();
										TiXmlAttribute *attr = col->FirstAttribute();
										while (attr != NULL) {
											if (string(attr->Name()) == "type") {
												column.type = attr->Value();
											}
											attr = attr->Next();
										}
										table.columns.push_back(column);
									}
									col = col->NextSiblingElement();
								}
							}
							tb = tb->NextSiblingElement();
						}
						t = t->NextSiblingElement();
						tables.push_back(table);
					}
				}
			}
			pack = pack->NextSiblingElement();
		}
		return true;
	}  
	return false;
}
Beispiel #24
0
void MeshCompiler::CompileArmature( TiXmlElement* Arm )
{
	if( Arm )
	{
		m_Header.m_HasSkeleton = true;
		TiXmlAttribute* ArmAttr = Arm->FirstAttribute();	// "frames"
		m_Header.m_NumFrames = ArmAttr->IntValue() + 1;	// + 1 for T-pose at frame 0
		for( TiXmlElement* Bone = Arm->FirstChildElement( "bonedef" ); Bone; Bone = Bone->NextSiblingElement( "bonedef" ) )
		{
			SNamedBone sbone;
			TiXmlAttribute* BoneAttr = Bone->FirstAttribute();
			const char* pName = BoneAttr->Value();
			sbone.m_Name = HashedString( pName );

			// Push an identity so frame 0 is the T-pose
			sbone.m_FrameQuats.PushBack( Quat() );
			sbone.m_FrameTransVecs.PushBack( Vector() );

			for( TiXmlElement* Frame = Bone->FirstChildElement( "frame" ); Frame; Frame = Frame->NextSiblingElement( "frame" ) )
			{
				Matrix FrameMatrix;
				TiXmlAttribute* FrameAttr = Frame->FirstAttribute();

				// In case I ever need separate frame values
				int FrameNum = FrameAttr->IntValue();
				Unused( FrameNum );

				FrameAttr = FrameAttr->Next();
				GetXMLMatrix( FrameAttr, FrameMatrix );

				Quat FrameQuat = FrameMatrix.ToQuaternion();
				Vector FrameTransVec = FrameMatrix.GetTranslationElements();

				sbone.m_FrameQuats.PushBack( FrameQuat );
				sbone.m_FrameTransVecs.PushBack( FrameTransVec );
			}

			m_Bones.PushBack( sbone );
			++m_Header.m_NumBones;
		}

		CompileAnimations( Arm );
	}
}
Beispiel #25
0
int em::EmXml::ClearRootAttr()
{
	bool bUpdated = false;
	int iResult = 0;
	TiXmlElement *pElemRoot = m_pDoc->RootElement();
	if(pElemRoot == NULL)
	{
		return 0;
	}
	
	
	while(pElemRoot->FirstAttribute())
	{
		pElemRoot->RemoveAttribute(pElemRoot->FirstAttribute()->Name());
		bUpdated = true;
	}

	m_bUpdated = bUpdated;
	return iResult;
}
Beispiel #26
0
void DataModel::loadStage()
{
    TiXmlDocument* myDocument = new TiXmlDocument();
    unsigned char* pBuffer = NULL;
    ssize_t bufferSize = 0;
    pBuffer = FileUtils::getInstance()->getFileData("stage.xml", "r", &bufferSize);
    if (pBuffer) {
        myDocument->Parse((const char*)pBuffer);
        TiXmlElement* stage = myDocument->RootElement();
        TiXmlElement* points = stage->FirstChildElement();
        TiXmlElement* point = points->FirstChildElement();
        while (points) {
            const char *name = points->Attribute("name");
            __Array *temp = __Array::create();
            
            while (point) {
                TiXmlAttribute *x = point->FirstAttribute();
                int pointX = x->IntValue();
                int pointY = x->Next()->IntValue();
                if (_winSize.height < 1100) {
                    pointY = pointY - 25;
                }
                temp->addObject(new MyPoint(pointX ,_winSize.height / 1280.0 * pointY));
                point = point->NextSiblingElement();
            }
            if (StringUtils::format("s9%d",flag9) == std::string(name)) {
                stage9.pushBack(temp);
                flag9++;
            }
            if (StringUtils::format("s5%d",flag5) == std::string(name)) {
                stage5.pushBack(temp);
                flag5++;
            }
            if (StringUtils::format("s6%d",flag6) == std::string(name)) {
                stage6.pushBack(temp);
                flag6++;
            }
            point = points->FirstChildElement();
            points = points->NextSiblingElement();
        }
        Ref *obj;
        MyPoint *p;
        for (auto a: stage5) {
            
            CCARRAY_FOREACH(a, obj)
            {
                p = (MyPoint *)obj;
            }
            
        }

    }
 
}
void EnemyManager::ReadXmlEnemyData(const char* filename)
{
	TiXmlDocument doc;
	if (doc.LoadFile(filename)) {
		doc.Print();
	} else {
		MyLog::put(__LINE__, __FILE__, "can not parse xml file.\n");
		return;
	}

	TiXmlElement* rootElement = doc.RootElement();
	TiXmlElement* keyElement = rootElement->FirstChildElement();

	while (keyElement) {
		EnemyData ed;
		TiXmlElement* ele = keyElement->FirstChildElement();
		TiXmlAttribute* coord = ele->FirstAttribute();
		ed.x = atoi(coord->Value());
		coord = coord->Next();
		ed.y = atoi(coord->Value());
		coord = coord->Next();
		ed.z = atoi(coord->Value());

		ele = ele->NextSiblingElement();
		TiXmlElement* cmdEle = ele->FirstChildElement();
		while (cmdEle) {
			TiXmlAttribute* cmdName = cmdEle->FirstAttribute();
			if (strcmp(cmdName->Value(), "MovingForward") == 0) {
				ed.vCmd.push_back(Job::eMovingForward);
			} else if (strcmp(cmdName->Value(), "TurningLeft") == 0) {
				ed.vCmd.push_back(Job::eTurningLeft);
			} else if (strcmp(cmdName->Value(), "TurningRight") == 0) {
				ed.vCmd.push_back(Job::eTurningRight);
			}
			cmdEle = cmdEle->NextSiblingElement();
		}

		vData.push_back(ed);
		keyElement = keyElement->NextSiblingElement();
	}
}
Beispiel #28
0
bool ParseButtonConfig(TiXmlElement *root, wConfigs &configs)
{
	auto config = configs.newConfig();
	if(config){
		//char configName[128] = "";
		TiXmlAttribute *rootAttribute = root->FirstAttribute();
		while(rootAttribute){
			if(strcmp(rootAttribute->Name(),"name") == 0){
				strcpy_s(config->name,rootAttribute->Value());
			}
			rootAttribute = rootAttribute->Next();
		}
		qDebug() << "config:" << QString::fromLocal8Bit(config->name);

		TiXmlElement *node = root->FirstChildElement();
		while(node){
			//qDebug() << cnt++ <<" " << node->Value();
			if(strcmp(node->Value(),"button") == 0){
				stButton *button = new stButton();
				int id = 0;
				TiXmlAttribute *nodeAttribute = node->FirstAttribute();
				while(nodeAttribute){
					//qDebug() << QString(nodeAttribute->Name()) <<":" << QString(nodeAttribute->Value());// << endl;
					if(strcmp(nodeAttribute->Name(),"id") == 0){
						id = atoi(nodeAttribute->Value());
					}else if(strcmp(nodeAttribute->Name(),"name") == 0){
						strcpy_s(button->m_name, nodeAttribute->Value());
					}
					nodeAttribute = nodeAttribute->Next();
				}
				button->id = id;
				if(node->FirstChild()){
				   strcpy_s(button->m_action, node->FirstChild()->Value());
				   //kill = QString::fromLocal8Bit(node->FirstChild()->Value());
				}
                qDebug() << id <<"," << QString::fromLocal8Bit(button->m_name) << "," << QString::fromLocal8Bit(button->m_action); //<< endl;
				config->buttons[id] = button;

			}else if(strcmp(node->Value(),"url") == 0){
				strcpy_s(config->url,node->FirstChild()->Value());
			}else if(strcmp(node->Value(),"workdir") == 0){
				strcpy_s(config->dir,node->FirstChild()->Value());
			}
			node = node->NextSiblingElement();
		}
		configs.push_back(config);
		return true;
	}
	return false;
}
Beispiel #29
0
void Session::load_metadata(fsom::Session* session, TiXmlElement* element ){
	TiXmlElement * metaElement = element->FirstChildElement( "MetaData" );
		if(metaElement){
			TiXmlAttribute* attribute = metaElement->FirstAttribute();
			  while(attribute){
			      std::string name(attribute->Name());
			      session->register_meta(name);
			      session->set_meta(name,std::string(attribute->Value()));
			      attribute = attribute->Next();
			  }
			  
			  
		}
}
Beispiel #30
0
int em::EmXml::ReadRootChildAttrList( EmVecMapStr &rVecMapStr )
{
	int iResult = 0;
	rVecMapStr.clear();

	TiXmlElement *pElemRoot = m_pDoc->RootElement();
	if(pElemRoot == NULL)
	{
		return 0;
	}
	
	TiXmlElement *pElemChild = pElemRoot->FirstChildElement();
	TiXmlAttribute *pAttrChild = NULL;
	EmMapStr MapStr;
	while(true)
	{
		if(pElemChild == NULL)
		{
			break;
		}
		
		if(pElemChild->Type() != TiXmlNode::TINYXML_ELEMENT)
		{
			continue;
		}
		
		MapStr.clear();
		
		pAttrChild = pElemChild->FirstAttribute();
		while(true)
		{
			if(pAttrChild == NULL)
			{
				break;
			}
			
			MapStr[ pAttrChild->Name() ] = pAttrChild->Value();
			
			pAttrChild = pAttrChild->Next();
		}
		
		rVecMapStr.push_back(MapStr);
		pElemChild = pElemChild->NextSiblingElement();
	}
	
	iResult = rVecMapStr.size();
	
	return iResult;
}