void CMainDlg::AddUserInfoToCrashDescriptorXML(CString sEmail, CString sDesc) { strconv_t strconv; TiXmlDocument doc; CString sFileName = g_CrashInfo.m_sErrorReportDirName + _T("\\crashrpt.xml"); bool bLoad = doc.LoadFile(strconv.t2a(sFileName.GetBuffer(0))); if(!bLoad) return; TiXmlNode* root = doc.FirstChild("CrashRpt"); if(!root) return; // Write user e-mail TiXmlElement* email = new TiXmlElement("UserEmail"); root->LinkEndChild(email); LPCSTR lpszEmail = strconv.t2a(sEmail.GetBuffer(0)); TiXmlText* email_text = new TiXmlText(lpszEmail); email->LinkEndChild(email_text); // Write problem description TiXmlElement* desc = new TiXmlElement("ProblemDescription"); root->LinkEndChild(desc); LPCSTR lpszDesc = strconv.t2a(sDesc.GetBuffer(0)); TiXmlText* desc_text = new TiXmlText(lpszDesc); desc->LinkEndChild(desc_text); doc.SaveFile(); }
//************************************ // Method: GetDocument // FullName: vtPhysics::pFactory::GetDocument // Access: public // Returns: TiXmlDocument* // Qualifier: // Parameter: XString filename //************************************ TiXmlDocument* pFactory::getDocument(XString filename) { XString fname(filename.Str()); if ( fname.Length() ) { XString fnameTest = ResolveFileName(fname.CStr()); if ( fnameTest.Length()) { TiXmlDocument* result = new TiXmlDocument(fnameTest.Str()); result->LoadFile(fnameTest.Str()); result->Parse(fnameTest.Str()); TiXmlNode* node = result->FirstChild( "vtPhysics" ); if (!node) { GetPMan()->m_Context->OutputToConsoleEx("PFactory : Couldn't load Document : %s",filename.Str()); return NULL; }else { return result; } } } return NULL; }
BOOL GetBkgPingCheckOpt(PBBS_BKG_PINGCHECK_OPT pPingOpt) { TiXmlDocument doc; const char *pszCustomDest = NULL; bool bOperating = false; int nBreakInt = 0; int nPingInt = 0; int nMaxCount = 0; if( CheckValidXML(&doc) == FALSE ) { return FALSE; } TiXmlElement* pElem = doc.FirstChild("BBS_WiFiConfig")->FirstChild("Setting")->FirstChild("Option")->FirstChildElement("BkgPingCheck"); pElem->QueryBoolAttribute("Operating", &bOperating); pElem->QueryIntAttribute("BreakInterval", &nBreakInt); pElem->QueryIntAttribute("PingInterval", &nPingInt); pElem->QueryIntAttribute("MaxCheckCnt", &nMaxCount); pszCustomDest = pElem->Attribute("CustomDestAddr"); pPingOpt->bOperating = bOperating; pPingOpt->dwBreakInterval = nBreakInt; pPingOpt->dwPingInterval = nPingInt; pPingOpt->dwMaxCheckCount = nMaxCount; mbstowcs(pPingOpt->tszCustomDestAddr, pszCustomDest, strlen(pszCustomDest)); return TRUE; }
void SipRedirectorPrivateStorageJoin::processNotify(const char* body) { // Initialize Tiny XML document object. TiXmlDocument document; TiXmlNode* dialog_info; if ( // Load the XML into it. document.Parse(body) && // Find the top element, which should be a <dialog-info>. (dialog_info = document.FirstChild("dialog-info")) != NULL && dialog_info->Type() == TiXmlNode::ELEMENT) { Os::Logger::instance().log(FAC_SIP, PRI_DEBUG, "SipRedirectorPrivateStorageJoin::processNotify " "Body parsed, <dialog-info> found"); // Find all the <dialog> elements. for (TiXmlNode* dialog = 0; (dialog = dialog_info->IterateChildren("dialog", dialog)); ) { // Process each <dialog> element. processNotifyDialogElement(dialog->ToElement()); } } else { // Report error. Os::Logger::instance().log(FAC_SIP, PRI_ERR, "SipRedirectorPrivateStorageJoin::processNotify " "NOTIFY body invalid: '%s'", body); } }
void Stage::loadDialogues(std::string file) { writeLogLine("Loading dialogues from XML."); char *archivo=new char[255]; strcpy(archivo,"stages/"); strcat(archivo,file.c_str()); strcat(archivo,"/dialogues.xml"); TiXmlDocument doc_t( archivo ); doc_t.LoadFile(); TiXmlDocument *doc; doc=&doc_t; TiXmlNode *dialogues_file=doc->FirstChild("DialoguesFile"); if(dialogues_file==NULL) return; for(TiXmlNode *dialogue_node=dialogues_file->FirstChild("dialogue"); dialogue_node!=NULL; dialogue_node=dialogue_node->NextSibling("dialogue")) { int frame=atoi(dialogue_node->ToElement()->Attribute("frame")); std::string text=dialogue_node->ToElement()->Attribute("text"); std::string path=dialogue_node->ToElement()->Attribute("path"); dialogues[frame]=new Dialogue(painter,sonido,receiver,text,painter->getTexture("stages/"+file+"/"+path)); } }
bool LanguageManager::loadFromFile(const char* file) { TiXmlDocument doc; doc.LoadFile(file); #ifdef WIN32 // seemingly unused const char* err = doc.ErrorDesc(); #endif TiXmlNode *cNode = doc.FirstChild("lang"); if (!cNode) return false; auto parseString = [this](TiXmlElement* str) { const char* name = str->Attribute("name"); const char* val = str->GetText(); if (!name || !val) return; LanguageString* temp = dynamic_cast<LanguageString*>(this->BaseManager::findItem(name)); if (!temp) { temp = new LanguageString(name); this->addItem( temp ); } #ifdef DESURA_OFFICAL_BUILD temp->ustr = val; #else std::vector<std::string> res; UTIL::STRING::tokenize(gcString(val), res, "Desura"); gcString out; for (size_t x=0; x<res.size(); x++) { out += res[x]; if (x+1 != res.size()) out += PRODUCT_NAME; } temp->ustr = out; #endif }; XML::for_each_child("str", cNode->FirstChild("strings"), parseString); #ifdef WIN32 XML::for_each_child("str", cNode->FirstChild("windows"), parseString); #else XML::for_each_child("str", cNode->FirstChild("linux"), parseString); #endif return true; }
int main() { TiXmlDocument doc; doc.Parse(testXml.c_str()); TiXmlNode* node = 0; TiXmlElement* requestElement = 0; node = doc.FirstChild("request"); assert(node); requestElement = node->ToElement(); assert(requestElement); string typeInfo(requestElement->Attribute("type")); if (typeInfo == "heartbeat") { cout << "Hey heartbeat" << endl; boost::replace_first(testXml,"request type=\"heartbeat\"", "request"); } cout << testXml << endl; return 0; }
int CCrashInfoReader::ParseCrashDescription(CString sFileName) { strconv_t strconv; TiXmlDocument doc; bool bOpen = doc.LoadFile(strconv.t2a(sFileName)); if(!bOpen) return 1; TiXmlHandle hRoot = doc.FirstChild("CrashRpt"); if(hRoot.ToElement()==NULL) return 1; TiXmlHandle hAppName = hRoot.FirstChild("AppName"); const char* szAppName = hAppName.FirstChild().ToText()->Value(); if(szAppName!=NULL) m_sAppName = strconv.utf82t(szAppName); TiXmlHandle hAppVersion = hRoot.FirstChild("AppVersion"); const char* szAppVersion = hAppVersion.FirstChild().ToText()->Value(); if(szAppVersion!=NULL) m_sAppVersion = strconv.utf82t(szAppVersion); TiXmlHandle hImageName = hRoot.FirstChild("ImageName"); const char* szImageName = hAppName.FirstChild().ToText()->Value(); if(szImageName!=NULL) m_sImageName = strconv.utf82t(szImageName); return 0; }
status_t Converter::ConvertFreeMind2PDoc() { BMessage *document = new BMessage(); BMessage *allNodes = new BMessage(); BMessage *allConnections = new BMessage(); char *xmlString; off_t start,end; middel.Set(400,400,600,550); in->Seek(0,SEEK_SET); start = in->Position(); in->Seek(0,SEEK_END); end = in->Position(); in->Seek(0,SEEK_SET); size_t size= end-start; xmlString=new char[size+1]; in->Read(xmlString, size); TiXmlDocument doc; doc.Parse(xmlString); delete xmlString; if (doc.Error()) return B_ERROR; else { TiXmlNode* node = NULL; TiXmlElement* element = NULL; node = doc.FirstChild("map"); node = node->FirstChild("node"); element = node->ToElement(); CreateNode(allNodes, allConnections,element,0,0); } document->AddMessage("PDocument::allConnections",allConnections); document->AddMessage("PDocument::allNodes",allNodes); status_t err= document->Flatten(out); }
void WriteToXml(string& strXml, vector<bool>& vecType,string& FileName) { COriFileOperate oriFile(FileName); size_t nVecSize = vecType.size(); if (strXml.find("chinese_simple") != -1) { for (size_t i=1;i<nVecSize;++i) { vecType[i] = false; } } char* szNumOrStrInfo = new char[nVecSize+1]; for (size_t i = 0; i < nVecSize; i++) { if (vecType[i]) { szNumOrStrInfo[i] = 'n'; } else { szNumOrStrInfo[i] = 's'; } } szNumOrStrInfo[nVecSize] = '\0'; TiXmlDocument* pXmlDoc = new TiXmlDocument; pXmlDoc->InsertEndChild(TiXmlElement("config")); TiXmlNode* pXmlNode = pXmlDoc->FirstChild("config"); pXmlNode->InsertEndChild(TiXmlElement("TableType")); TiXmlElement* pXmlElem = pXmlNode->FirstChildElement("TableType"); pXmlElem->InsertEndChild(TiXmlText("S")); string str = szNumOrStrInfo; string str1 = oriFile.GetDataByRowCol(0,0); transform(str1.begin(),str1.end(),str1.begin(),toupper); for(uint32 i=1;i<=str.size();i++) { TiXmlElement* cxn = new TiXmlElement("Col"); pXmlNode->LinkEndChild(cxn); // cxn->SetAttribute("ColNum",i); if(str1!="NOTE:") { cxn->SetAttribute("Name",oriFile.GetDataByRowCol(0,i-1).c_str()); } else { cxn->SetAttribute("Name",oriFile.GetDataByRowCol(1,i-1).c_str()); } string ss; stringstream temp; temp<<szNumOrStrInfo[i-1]; temp>>ss; cxn->SetAttribute("Type",ss); } pXmlDoc->SaveFile(strXml); delete pXmlDoc; pXmlDoc = NULL; delete[] szNumOrStrInfo; szNumOrStrInfo = NULL; }
BOOL GetPowerOpt(int *pnAllowSuspendMode) { TiXmlDocument doc; int nAllowSuspendMode = 0; int nResult = TIXML_NO_ATTRIBUTE; if( CheckValidXML(&doc) == FALSE ) { return FALSE; } TiXmlElement* pElem = doc.FirstChild("BBS_WiFiConfig")->FirstChild("Setting")->FirstChild("Option")->FirstChildElement("PowerOption"); nResult = pElem->QueryIntAttribute("AllowSuspend", pnAllowSuspendMode); // 초기값이 설정되지 않았을때는, 연결된 상태에서 SuspendMode 허용 기본 설정 if( nResult == TIXML_WRONG_TYPE ) { *pnAllowSuspendMode = -1; } else if ( nResult == TIXML_NO_ATTRIBUTE ) { RETAILMSG(1, (TEXT("[PSH] ERROR \r\n") )); } return TRUE; }
bool CArtist::Save(TiXmlNode *node, const CStdString &tag, const CStdString& strPath) { if (!node) return false; // we start with a <tag> tag TiXmlElement artistElement(tag.c_str()); TiXmlNode *artist = node->InsertEndChild(artistElement); if (!artist) return false; XMLUtils::SetString(artist, "name", strArtist); XMLUtils::SetStringArray(artist, "genre", genre); XMLUtils::SetStringArray(artist, "style", styles); XMLUtils::SetStringArray(artist, "mood", moods); XMLUtils::SetStringArray(artist, "yearsactive", yearsActive); XMLUtils::SetStringArray(artist, "instruments", instruments); XMLUtils::SetString(artist, "born", strBorn); XMLUtils::SetString(artist, "formed", strFormed); XMLUtils::SetString(artist, "biography", strBiography); XMLUtils::SetString(artist, "died", strDied); XMLUtils::SetString(artist, "disbanded", strDisbanded); if (!thumbURL.m_xml.empty()) { TiXmlDocument doc; doc.Parse(thumbURL.m_xml); const TiXmlNode* thumb = doc.FirstChild("thumb"); while (thumb) { artist->InsertEndChild(*thumb); thumb = thumb->NextSibling("thumb"); } } XMLUtils::SetString(artist, "path", strPath); if (fanart.m_xml.size()) { TiXmlDocument doc; doc.Parse(fanart.m_xml); artist->InsertEndChild(*doc.RootElement()); } // albums for (vector< pair<CStdString,CStdString> >::const_iterator it = discography.begin(); it != discography.end(); ++it) { // add a <album> tag TiXmlElement cast("album"); TiXmlNode *node = artist->InsertEndChild(cast); TiXmlElement title("title"); TiXmlNode *titleNode = node->InsertEndChild(title); TiXmlText name(it->first); titleNode->InsertEndChild(name); TiXmlElement year("year"); TiXmlNode *yearNode = node->InsertEndChild(year); TiXmlText name2(it->second); yearNode->InsertEndChild(name2); } return true; }
int ParseCrashInfo(LPCSTR text, CString& sAppName, CString& sImageName, CString& sSubject, CString& sMailTo, CString& sUrl, UINT (*puPriorities)[3], CString& sZipName) { TiXmlDocument doc; doc.Parse(text); if(doc.Error()) return 1; TiXmlHandle hRoot = doc.FirstChild("crashrpt"); if(hRoot.ToElement()==NULL) return 1; const char* pszAppName = hRoot.ToElement()->Attribute("appname"); const char* pszImageName = hRoot.ToElement()->Attribute("imagename"); const char* pszSubject = hRoot.ToElement()->Attribute("subject"); const char* pszMailTo = hRoot.ToElement()->Attribute("mailto"); const char* pszUrl = hRoot.ToElement()->Attribute("url"); const char* pszZipName = hRoot.ToElement()->Attribute("zipname"); const char* pszHttpPriority = hRoot.ToElement()->Attribute("http_priority"); const char* pszSmtpPriority = hRoot.ToElement()->Attribute("smtp_priority"); const char* pszMapiPriority = hRoot.ToElement()->Attribute("mapi_priority"); if(pszAppName) sAppName = pszAppName; if(pszImageName) sImageName = pszImageName; if(pszSubject) sSubject = pszSubject; if(pszMailTo!=NULL) sMailTo = pszMailTo; if(pszUrl!=NULL) sUrl = pszUrl; if(pszZipName!=NULL) sZipName = pszZipName; if(pszHttpPriority!=NULL) (*puPriorities)[CR_HTTP] = atoi(pszHttpPriority); else (*puPriorities)[CR_HTTP] = 0; if(pszSmtpPriority!=NULL) (*puPriorities)[CR_SMTP] = atoi(pszSmtpPriority); else (*puPriorities)[CR_SMTP] = 0; if(pszMapiPriority!=NULL) (*puPriorities)[CR_SMAPI] = atoi(pszMapiPriority); else (*puPriorities)[CR_SMAPI] = 0; return 0; }
void CSvsFile::LoadXML() { UnloadXML(); TiXmlDocument XmlDoc; XmlDoc.SetCondenseWhiteSpace(false); ifstream iXML( m_strFile.c_str() ); if (!iXML) { GenErr("技能配置表转换文件读取错误", m_strFile); } iXML>>XmlDoc; iXML.close(); TiXmlNode* pBody = XmlDoc.FirstChild("body"); TiXmlNode* pTable = pBody->FirstChild("table"); for ( TiXmlNode* pTr = pTable->FirstChild(); pTr; pTr = pTr->NextSibling() ) { TiXmlElement* pElemet = pTr->ToElement(); if (!pElemet) continue; if(pElemet->ValueStr() != "tr") continue; m_vecTR.resize(m_vecTR.size() + 1); TableRow& vecTD = m_vecTR.back(); for ( TiXmlNode* pTd = pTr->FirstChild(); pTd; pTd=pTd->NextSibling() ) { TiXmlElement* pElemet = pTd->ToElement(); if (!pElemet) continue; if(pElemet->ValueStr() != "td") continue; TiXmlNode* pParagraph = pTd->FirstChild(); TiXmlElement* pParaElemet = pParagraph->ToElement(); if(!pParaElemet || pParaElemet->ValueStr() != "p") { GenErr("<td>读取<p>不存在"); } TableData aTD; aTD.m_eTDType = GetTableDataType(pParaElemet->Attribute("t")); if(pParaElemet->FirstChild()) { aTD.m_sTDValue = utf8_to_gbk(pParaElemet->GetText()); XMLDecode(aTD.m_sTDValue); } vecTD.push_back(aTD); } } }
RobotInterface::Robot& RobotInterface::XMLReader::Private::readRobotFile(const std::string &fileName) { filename = fileName; #ifdef WIN32 std::replace(filename.begin(), filename.end(), '/', '\\'); #endif curr_filename = fileName; #ifdef WIN32 path = filename.substr(0, filename.rfind("\\")); #else // WIN32 path = filename.substr(0, filename.rfind("/")); #endif //WIN32 yDebug() << "Reading file" << filename.c_str(); TiXmlDocument *doc = new TiXmlDocument(filename.c_str()); if (!doc->LoadFile()) { SYNTAX_ERROR(doc->ErrorRow()) << doc->ErrorDesc(); } if (!doc->RootElement()) { SYNTAX_ERROR(doc->Row()) << "No root element."; } for (TiXmlNode* childNode = doc->FirstChild(); childNode != 0; childNode = childNode->NextSibling()) { if (childNode->Type() == TiXmlNode::TINYXML_UNKNOWN) { if(dtd.parse(childNode->ToUnknown(), curr_filename)) { break; } } } if (!dtd.valid()) { SYNTAX_WARNING(doc->Row()) << "No DTD found. Assuming version robotInterfaceV1.0"; dtd.setDefault(); dtd.type = RobotInterfaceDTD::DocTypeRobot; } if(dtd.type != RobotInterfaceDTD::DocTypeRobot) { SYNTAX_WARNING(doc->Row()) << "Expected document of type" << DocTypeToString(RobotInterfaceDTD::DocTypeRobot) << ". Found" << DocTypeToString(dtd.type); } if(dtd.majorVersion != 1 || dtd.minorVersion != 0) { SYNTAX_WARNING(doc->Row()) << "Only robotInterface DTD version 1.0 is supported"; } readRobotTag(doc->RootElement()); delete doc; // yDebug() << robot; return robot; }
int main() { std::string str = "<ToDo><Item priority=\"1st priority\"> item 1</Item><Item priority=\"2nd priority\"> item 2</Item></ToDo>"; const char *filedata = str.c_str(); std::cout << "Hello World!" << std::endl; TiXmlDocument doc; doc.Parse((const char*)filedata, 0, TIXML_ENCODING_UTF8); TiXmlElement* child = doc.FirstChild( "ToDo" )->FirstChild( "Item" )->ToElement(); TiXmlElement* element = doc.RootElement(); std::cout << "Elem: " << child->Attribute("priority") << std::endl; return 0; }
void CMainDlg::AddUserInfoToCrashDescriptorXML(CString sEmail, CString sDesc) { USES_CONVERSION; HZIP hz = CreateZip(m_sZipName, NULL); TStrStrMap::iterator cur = m_pUDFiles.begin(); unsigned int i; for (i = 0; i < m_pUDFiles.size(); i++, cur++) { CString sFileName = cur->first.c_str(); sFileName = sFileName.Mid(sFileName.ReverseFind('\\')+1); if(sFileName.CompareNoCase(_T("crashrpt.xml"))==0) { TiXmlDocument doc; bool bLoad = doc.LoadFile(cur->first.c_str()); if(!bLoad) return; TiXmlNode* root = doc.FirstChild("CrashRpt"); if(!root) return; // Write user e-mail TiXmlElement* email = new TiXmlElement("UserEmail"); root->LinkEndChild(email); LPSTR lpszEmail = T2A(sEmail.GetBuffer(0)); TiXmlText* email_text = new TiXmlText(lpszEmail); email->LinkEndChild(email_text); // Write problem description TiXmlElement* desc = new TiXmlElement("ProblemDescription"); root->LinkEndChild(desc); LPSTR lpszDesc = T2A(sDesc.GetBuffer(0)); TiXmlText* desc_text = new TiXmlText(lpszDesc); desc->LinkEndChild(desc_text); doc.SaveFile(); } LPTSTR lptszFilePath = A2T((char*)cur->first.c_str()); ZRESULT zr = ZipAdd(hz, sFileName, lptszFilePath); ATLASSERT(zr==ZR_OK); zr; } CloseZip(hz); }
bool SVG::read( const char* data ) { TiXmlDocument doc; doc.Parse( data ); if (doc.Error()) { return false; } TiXmlElement* root = doc.FirstChild( "svg" )->ToElement(); recursive_parse( root ); // get bounds information from the svg file, ignoring non-pixel values string numberWithUnitString; regex numberWithUnitPattern( "^(-?\\d+)(px)?$" ); _handler->_minX = 0.0f; if ( root->QueryStringAttribute( "x", &numberWithUnitString ) == TIXML_SUCCESS ) { match_results<string::const_iterator> matches; if ( regex_search( numberWithUnitString, matches, numberWithUnitPattern ) ) { _handler->_minX = ::atof( matches[1].str().c_str() ); } } _handler->_minY = 0.0f; if ( root->QueryStringAttribute( "y", &numberWithUnitString ) == TIXML_SUCCESS ) { match_results<string::const_iterator> matches; if ( regex_search( numberWithUnitString, matches, numberWithUnitPattern ) ) { _handler->_minY = ::atof( matches[1].str().c_str() ); } } _handler->_width = 0.0f; if ( root->QueryStringAttribute( "width", &numberWithUnitString ) == TIXML_SUCCESS ) { match_results<string::const_iterator> matches; if ( regex_search( numberWithUnitString, matches, numberWithUnitPattern ) ) { _handler->_width = ::atof( matches[1].str().c_str() ); } } _handler->_height = 0.0f; if ( root->QueryStringAttribute( "height", &numberWithUnitString ) == TIXML_SUCCESS ) { match_results<string::const_iterator> matches; if ( regex_search( numberWithUnitString, matches, numberWithUnitPattern ) ) { _handler->_height = ::atof( matches[1].str().c_str() ); } } return true; }
void BulletMLParserTinyXML::parseImpl(TiXmlDocument& doc) { if (doc.Error()) { throw BulletMLError(doc.Value() + ": " + doc.ErrorDesc()); } TiXmlNode* node; for (node = doc.FirstChild(); node; node = node->NextSibling()) { if (node->ToElement() != 0) { getTree(node); break; } } }
bool RequestLCGetVideoTask::HandleCallback(const string& url, bool requestRet, const char* buf, int size) { FileLog("httprequest", "RequestLCGetVideoTask::HandleResult( " "url : %s," "requestRet : %s " ")", url.c_str(), requestRet?"true":"false" ); if (size < MAX_LOG_BUFFER) { FileLog("httprequest", "RequestLCGetVideoTask::HandleResult( buf( %d ) : %s )", size, buf); } string errnum = ""; string errmsg = ""; string videoUrl = ""; bool bFlag = false; bool bContinue = true; if (requestRet) { // request success TiXmlDocument doc; if( HandleResult(buf, size, errnum, errmsg, doc, &bContinue) ) { bFlag = true; TiXmlNode *rootNode = doc.FirstChild(COMMON_ROOT); if (NULL != rootNode) { // group list TiXmlNode *videoNode = rootNode->FirstChild(LC_GETVIDEO_VIDEO_URL); if (NULL != videoNode) { TiXmlElement* videoUrlElement = videoNode->ToElement(); if (NULL != videoUrlElement) { videoUrl = videoUrlElement->GetText(); } } } } } else { // request fail errnum = LOCAL_ERROR_CODE_TIMEOUT; errmsg = LOCAL_ERROR_CODE_TIMEOUT_DESC; } if( bContinue && mpCallback != NULL ) { mpCallback->OnGetVideo(bFlag, errnum, errmsg, videoUrl, this); } return bFlag; }
void CComponent_Animation::Load(const std::string &filepath) { TiXmlDocument doc; bool load = doc.LoadFile((StrUtl::FormatString("%s/data/res/tex/%s/%s", fileSystem->GetBasePath().c_str(), filepath.c_str(), ANIMCONF_DEFAULT_NAME)).c_str()); ASSERT(load); TiXmlElement *animRoot = (TiXmlElement *)doc.FirstChild(); std::string animName = animRoot->Attribute("Name"); TiXmlElement *sequence; FOR_EACH_ELEM(animRoot, sequence) { animation_t animation; std::string sequenceName = sequence->Attribute("Name"); animation.frameInterval = atoi(sequence->Attribute("FrameInterval")); TiXmlElement *frameElem; FOR_EACH_ELEM(sequence, frameElem) { int id = atoi(frameElem->Attribute("ID")); std::string path = frameElem->Attribute("Path"); frame_t frame; frame.id = id; frame.texture = resMgr->GetTexture(StrUtl::FormatString("data/res/tex/%s/%s", filepath.c_str(), path.c_str()), CColor(255, 0, 255)); std::string flags; if (frameElem->Attribute("Flags") != NULL) { flags = frameElem->Attribute("Flags"); } if(flags.find("hrev") != std::string::npos) { frame.hrev = true; } if (frameElem->Attribute("OffsetX") != NULL) { frame.offsetX = (float)atoi(frameElem->Attribute("OffsetX")); } if (frameElem->Attribute("OffsetY") != NULL) { frame.offsetY = (float)atoi(frameElem->Attribute("OffsetY")); } animation_t::framePair_t framePair(id, frame); animation.frames.insert(framePair); }
void zzzSndSystem::LoadSounds() { //read xml & load sets DataStreamPtr data = ResourceGroupManager::getSingleton().openResource("sounds.xml"); String str = data->getAsString(); TiXmlDocument doc; doc.Parse(str.c_str()); if (!doc.Error()) { TiXmlNode* node; node=doc.FirstChild(); node=node->FirstChild(); for (;node!=0;node=node->NextSibling()) { if (node->Type() == TiXmlNode::ELEMENT) { //get params String name = ""; String file = ""; if (strcmp(node->Value(), "sound") == 0) { TiXmlAttribute* att = node->ToElement()->FirstAttribute(); while (att) { if (strcmp(att->Name(), "name") == 0) { name = att->Value(); } else if (strcmp(att->Name(), "file") == 0) { file = att->Value(); } att = att->Next(); } if (name.length() > 0) { SND->LoadSound(name, file); } } } } } else { throw Exception(Exception::ERR_FILE_NOT_FOUND, std::string(doc.ErrorDesc()) + " : particles.xml", __FUNCTION__); } }
void XMLUtils::LoadXMLFile( TiXmlDocument& doc, bool condenseWhiteSpace, const wxString& path ) { if ( path.empty() ) { THROW_WXFBEX( _("LoadXMLFile needs a path") ) } if ( !::wxFileExists( path ) ) { THROW_WXFBEX( _("The file does not exist.\nFile: ") << path ) } TiXmlBase::SetCondenseWhiteSpace( condenseWhiteSpace ); doc.SetValue( std::string( path.mb_str( wxConvFile ) ) ); if ( !doc.LoadFile() ) { // Ask user to all wxFB to convert the file to UTF-8 and add the XML declaration wxString msg = _("This xml file could not be loaded. This could be the result of an unsupported encoding.\n"); msg += _("Would you like wxFormBuilder to backup the file and convert it to UTF-8\?\n"); msg += _("You will be prompted for the original encoding.\n\n"); msg += _("Path: "); msg += path; if ( wxNO == wxMessageBox( msg, _("Unable to load file"), wxICON_QUESTION | wxYES_NO | wxYES_DEFAULT, wxTheApp->GetTopWindow() ) ) { // User declined, give up THROW_WXFBEX( _("Unable to load file: ") << path ); } // User accepted, convert the file wxFontEncoding chosenEncoding = StringUtils::GetEncodingFromUser( _("Please choose the original encoding.") ); if ( wxFONTENCODING_MAX == chosenEncoding ) { THROW_WXFBEX( _("Unable to load file: ") << path ); } ConvertAndAddDeclaration( path, chosenEncoding ); LoadXMLFile( doc, condenseWhiteSpace, path ); } TiXmlDeclaration* declaration = NULL; TiXmlNode* firstChild = doc.FirstChild(); if ( firstChild ) { declaration = firstChild->ToDeclaration(); } LoadXMLFileImp( doc, condenseWhiteSpace, path, declaration ); }
void CreateMCFThread::retrieveBranchList(std::vector<UserCore::Item::BranchInfo*> &outList) { TiXmlDocument doc; getWebCore()->getItemInfo(getItemId(), doc, MCFBranch(), MCFBuild()); TiXmlNode *uNode = doc.FirstChild("iteminfo"); if (!uNode) throw gcException(ERR_BADXML); XML::for_each_child("platform", uNode->FirstChildElement("platforms"), [this, &outList](TiXmlElement* platform) { this->processGames(outList, platform); }); }
BOOL SetPowerOpt(BOOL bAllowSuspendMode) { TiXmlDocument doc; if( CheckValidXML(&doc) == FALSE ) { return FALSE; } TiXmlElement* pElem = doc.FirstChild("BBS_WiFiConfig")->FirstChild("Setting")->FirstChild("Option")->FirstChildElement("PowerOption"); pElem->SetAttribute("AllowSuspend", bAllowSuspendMode); return doc.SaveFile(); }
void Tileset::ParseTsxFile(const std::string &fileName) { // Most of this is copy-pasted from Map::ParseFile() char* fileText; int fileSize; // Open the file for reading. FILE *file = fopen(fileName.c_str(), "rb"); // Check if the file could not be opened. if (!file) { has_error = true; error_code = TMX_COULDNT_OPEN; error_text = "Could not open the file " + fileName; return; } // Find out the file size. fseek(file, 0, SEEK_END); fileSize = ftell(file); fseek(file, 0, SEEK_SET); // Allocate memory for the file and read it into the memory. fileText = new char[fileSize]; fread(fileText, 1, fileSize, file); fclose(file); // Copy the contents into a C++ string and delete it from memory. std::string text(fileText, fileText+fileSize); delete [] fileText; // Create a tiny xml document and use it to parse the text. TiXmlDocument doc; doc.Parse(text.c_str()); if (doc.Error()) { has_error = true; error_code = TMX_PARSING_ERROR; error_text = doc.ErrorDesc(); return; } else { ParseElement(doc.FirstChild("tileset")->ToElement()); } }
BOOL SetDefPrefNetOpt(BBS_DEF_PREF_NETWORK_INFO defPrefNetInfo) { TiXmlDocument doc; char szIPAddr[18] = {'\0',}; char szSubNetMask[18] = {'\0',}; char szGateWay[18] = {'\0',}; char szDnsAddr[18] = {'\0',}; char szSSID[255] = {'\0',}; char szNetworkKey[128] = {'\0',}; if( CheckValidXML(&doc) == FALSE ) { return FALSE; } wcstombs(szIPAddr, defPrefNetInfo.tszIPAddr, _tcslen(defPrefNetInfo.tszIPAddr) ); wcstombs(szSubNetMask, defPrefNetInfo.tszSubNetMask, _tcslen(defPrefNetInfo.tszSubNetMask) ); wcstombs(szGateWay, defPrefNetInfo.tszGateWay, _tcslen(defPrefNetInfo.tszGateWay) ); wcstombs(szDnsAddr, defPrefNetInfo.tszDnsAddr, _tcslen(defPrefNetInfo.tszDnsAddr) ); wcstombs(szSSID, defPrefNetInfo.tszSSID, _tcslen(defPrefNetInfo.tszSSID) ); wcstombs(szNetworkKey, defPrefNetInfo.tszNetworkKey, _tcslen(defPrefNetInfo.tszNetworkKey) ); TiXmlElement* pElem = doc.FirstChild("BBS_WiFiConfig")->FirstChild("Setting")->FirstChildElement("DefaultPreferNet"); pElem->SetAttribute("Enable", defPrefNetInfo.bEnable); pElem->SetAttribute("DHCP", defPrefNetInfo.bDHCP); pElem->SetAttribute("Hidden", defPrefNetInfo.bHidden); pElem->SetAttribute("IP", szIPAddr); pElem->SetAttribute("Subnet", szSubNetMask); pElem->SetAttribute("Gateway", szGateWay); pElem->SetAttribute("DNS", szDnsAddr); pElem->SetAttribute("SSID", szSSID); pElem->SetAttribute("Auth", defPrefNetInfo.dwAuthType); pElem->SetAttribute("Encr", defPrefNetInfo.dwEncrType); pElem->SetAttribute("Key", szNetworkKey); pElem->SetAttribute("KeyIdx", defPrefNetInfo.dwKeyIndex); pElem->SetAttribute("Hex_16", defPrefNetInfo.bHexKey); return doc.SaveFile(); }
BOOL GetDefPrefNetOpt(BBS_DEF_PREF_NETWORK_INFO *pDefPrefNetInfo) { TiXmlDocument doc; const char *pszIPAddr = NULL; const char *pszSubNetMask = NULL; const char *pszGateWay = NULL; const char *pszDnsAddr = NULL; const char *pszSSID = NULL; const char *pszNetworkKey = NULL; if( CheckValidXML(&doc) == FALSE ) { return FALSE; } TiXmlElement* pElem = doc.FirstChild("BBS_WiFiConfig")->FirstChild("Setting")->FirstChildElement("DefaultPreferNet"); pElem->Attribute("Enable", (int*)&pDefPrefNetInfo->bEnable); pElem->Attribute("DHCP", (int*)&pDefPrefNetInfo->bDHCP); pElem->Attribute("Hidden", (int*)&pDefPrefNetInfo->bHidden); pszIPAddr = pElem->Attribute("IP"); pszSubNetMask = pElem->Attribute("Subnet"); pszGateWay = pElem->Attribute("Gateway"); pszDnsAddr = pElem->Attribute("DNS"); pszSSID = pElem->Attribute("SSID"); pElem->Attribute("Auth", (int*)&pDefPrefNetInfo->dwAuthType); pElem->Attribute("Encr", (int*)&pDefPrefNetInfo->dwEncrType); pszNetworkKey = pElem->Attribute("Key"); pElem->Attribute("KeyIdx", (int*)&pDefPrefNetInfo->dwKeyIndex); pElem->Attribute("Hex_16", (int*)&pDefPrefNetInfo->bHexKey); mbstowcs(pDefPrefNetInfo->tszIPAddr, pszIPAddr, strlen(pszIPAddr)); mbstowcs(pDefPrefNetInfo->tszSubNetMask, pszSubNetMask, strlen(pszSubNetMask)); mbstowcs(pDefPrefNetInfo->tszGateWay, pszGateWay, strlen(pszGateWay)); mbstowcs(pDefPrefNetInfo->tszDnsAddr, pszDnsAddr, strlen(pszDnsAddr)); mbstowcs(pDefPrefNetInfo->tszSSID, pszSSID, strlen(pszSSID)); mbstowcs(pDefPrefNetInfo->tszNetworkKey, pszNetworkKey, strlen(pszNetworkKey)); return TRUE; }
RobotInterface::ActionList RobotInterface::XMLReader::Private::readActionsFile(const std::string &fileName) { std::string old_filename = curr_filename; curr_filename = fileName; yDebug() << "Reading file" << fileName.c_str(); TiXmlDocument *doc = new TiXmlDocument(fileName.c_str()); if (!doc->LoadFile()) { SYNTAX_ERROR(doc->ErrorRow()) << doc->ErrorDesc(); } if (!doc->RootElement()) { SYNTAX_ERROR(doc->Row()) << "No root element."; } RobotInterfaceDTD actionsFileDTD; for (TiXmlNode* childNode = doc->FirstChild(); childNode != 0; childNode = childNode->NextSibling()) { if (childNode->Type() == TiXmlNode::TINYXML_UNKNOWN) { if(actionsFileDTD.parse(childNode->ToUnknown(), curr_filename)) { break; } } } if (!actionsFileDTD.valid()) { SYNTAX_WARNING(doc->Row()) << "No DTD found. Assuming version robotInterfaceV1.0"; actionsFileDTD.setDefault(); actionsFileDTD.type = RobotInterfaceDTD::DocTypeActions; } if (actionsFileDTD.type != RobotInterfaceDTD::DocTypeActions) { SYNTAX_ERROR(doc->Row()) << "Expected document of type" << DocTypeToString(RobotInterfaceDTD::DocTypeActions) << ". Found" << DocTypeToString(actionsFileDTD.type); } if (actionsFileDTD.majorVersion != dtd.majorVersion) { SYNTAX_ERROR(doc->Row()) << "Trying to import a file with a different robotInterface DTD version"; } RobotInterface::ActionList actions = readActionsTag(doc->RootElement()); delete doc; curr_filename = old_filename; return actions; }
int main(int argc, char * argv[]) { cout << "begin test xml : " << endl; CxApplication::init(argc, argv); string sFilePath = CxFileSystem::mergeFilePath(CxApplication::applicationPath(), "cics"); sFilePath = CxFileSystem::mergeFilePath(sFilePath, "template_00304.xml"); if (! CxFileSystem::isExist(sFilePath)) return 0; string sReceived; CxFile::load(sFilePath, sReceived); TiXmlDocument doc; doc.Parse(sReceived.c_str()); // doc.LoadFile(sFilePath); TiXmlNode * root = doc.FirstChild(); if (root->Type() == TiXmlNode::TINYXML_DECLARATION) root = root->NextSibling(); cout << string(0, ' ') << root->Value() << endl; for( TiXmlElement * node1Level = root->FirstChildElement(); node1Level; node1Level = node1Level->NextSiblingElement() ) { cout << string(4, ' ') << node1Level->Value() << endl; for( TiXmlElement * node2Level = node1Level->FirstChildElement(); node2Level; node2Level = node2Level->NextSiblingElement() ) { string sValue; for( TiXmlNode * node3Level = node2Level->FirstChild(); node3Level; node3Level = node3Level->NextSibling() ) { if (node3Level->Type() == TiXmlNode::TINYXML_TEXT) { sValue = node3Level->ToText()->Value(); break; } } cout << string(8, ' ') << node2Level->Value() << "=" << sValue << endl; } } return 0; }