예제 #1
0
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__);
	}
}
예제 #2
0
double leatherman::getColladaFileScale(std::string resource)
{
  static std::map<std::string, float> rescale_cache;

  // Try to read unit to meter conversion ratio from mesh. Only valid in Collada XML formats. 
  TiXmlDocument xmlDoc;
  float unit_scale(1.0);
  resource_retriever::Retriever retriever;
  resource_retriever::MemoryResource res;
  try
  {
    res = retriever.get(resource);
  }
  catch (resource_retriever::Exception& e)
  {
    ROS_ERROR("%s", e.what());
    return unit_scale;
  }

  if (res.size == 0)
  {
    return unit_scale;
  }


  // Use the resource retriever to get the data.
  const char * data = reinterpret_cast<const char * > (res.data.get());
  xmlDoc.Parse(data);

  // Find the appropriate element if it exists
  if(!xmlDoc.Error())
  {
    TiXmlElement * colladaXml = xmlDoc.FirstChildElement("COLLADA");
    if(colladaXml)
    {
      TiXmlElement *assetXml = colladaXml->FirstChildElement("asset");
      if(assetXml)
      {
        TiXmlElement *unitXml = assetXml->FirstChildElement("unit");
        if (unitXml && unitXml->Attribute("meter"))
        {
          // Failing to convert leaves unit_scale as the default.
          if(unitXml->QueryFloatAttribute("meter", &unit_scale) != 0)
            ROS_WARN_STREAM("getMeshUnitRescale::Failed to convert unit element meter attribute to determine scaling. unit element: " << *unitXml);
        }
      }
    }
  }
  return unit_scale;
}
예제 #3
0
CReadXML::CReadXML(string xmlpath)
{
#if CC_TARGET_PLATFORM == CC_PLATFORM_ANDROID
	unsigned long size = 0;
	char* pFileContent = (char*)CCFileUtils::sharedFileUtils()->getFileData(xmlpath.c_str(),"r",&size);
	TiXmlDocument* document = new TiXmlDocument();
	document->Parse(pFileContent,0,TIXML_ENCODING_UTF8);
#endif
#if CC_TARGET_PLATFORM ==  CC_PLATFORM_WIN32 || CC_TARGET_PLATFORM == CC_PLATFORM_IOS
	TiXmlDocument* document = new TiXmlDocument(xmlpath.c_str());
	document->LoadFile();
#endif
	parseXML(document);
}
예제 #4
0
	bool UIManager::LoadScreens ( string rootXML, IArchive *pArchive )
	///////////////////////////////////////////////////////////////////////////
	{
		if ( pArchive == NULL )
			return false;

		istream *pStream = pArchive->LoadFile ( rootXML );

		// File wasn't loaded properly
		if ( !pStream )
			return false;

		string xmlData;

		// Read the entire document
		while ( !pStream->eof() )
		{
			string xmlLine;
			getline ( *pStream, xmlLine );

			xmlData += xmlLine + "\n";
		}

		// Document is loaded, finally parse it
		TiXmlDocument document;
		document.Parse ( xmlData.c_str() );

		// We no longer need the open file
		delete pStream;

		// Loop through and load each screen
		xpath_processor xpath ( document.RootElement(), "/interface/screen" );
		int xpathsize = xpath.u_compute_xpath_node_set();
		for ( int i = 0; i < xpathsize; i++ )
		{
			Screen *pScreen = new Screen ( );

			// If the screen loads properly, build it
			if ( pScreen->LoadScreen ( (TiXmlElement *)xpath.XNp_get_xpath_node ( i ) ) )
			{
				_screens[ pScreen->id() ] = pScreen;
				_pCurrentScreen = pScreen;
				pScreen->BuildScreen ( &_skin );
			}
			else
				delete pScreen;
		}

		return true;
	}
예제 #5
0
XN_C_API XnStatus xnContextRunXmlScript(XnContext* pContext, const XnChar* xmlScript, XnEnumerationErrors* pErrors)
{
    XnStatus nRetVal = XN_STATUS_OK;

    TiXmlDocument doc;
    if (!doc.Parse(xmlScript))
    {
        XN_LOG_ERROR_RETURN(XN_STATUS_CORRUPT_FILE, XN_MASK_OPEN_NI,
                            "Failed loading xml: %s [row %d, column %d]",
                            doc.ErrorDesc(), doc.ErrorRow(), doc.ErrorCol());
    }

    return RunXmlScriptImpl(pContext, &doc, pErrors);
}
예제 #6
0
파일: zPanelLib.cpp 프로젝트: zapline/zlib
BOOL CPanelBase::LoadXmlData( LPCSTR lpszXml )
{
    TiXmlDocument xmlDoc;
    {
        xmlDoc.Parse(lpszXml, NULL, TIXML_ENCODING_UTF8);
    }

    if (xmlDoc.Error())
        return FALSE;

    TiXmlElement *pXmlRootElem = xmlDoc.RootElement();

    return LoadXml(pXmlRootElem);
}
예제 #7
0
void ThingTypeManager::loadXml(const std::string& file)
{
    try {
        if(!isOtbLoaded())
            stdext::throw_exception("OTB must be loaded before XML");

        TiXmlDocument doc;
        doc.Parse(g_resources.readFileContents(file).c_str());
        if(doc.Error())
            stdext::throw_exception(stdext::format("failed to parse '%s': '%s'", file, doc.ErrorDesc()));

        TiXmlElement* root = doc.FirstChildElement();
        if(!root || root->ValueTStr() != "items")
            stdext::throw_exception("invalid root tag name");

        for(TiXmlElement *element = root->FirstChildElement(); element; element = element->NextSiblingElement()) {
            if(unlikely(element->ValueTStr() != "item"))
                continue;

            uint16 id = element->readType<uint16>("id");
            if(id != 0) {
                std::vector<std::string> s_ids = stdext::split(element->Attribute("id"), ";");
                for(const std::string& s : s_ids) {
                    std::vector<int32> ids = stdext::split<int32>(s, "-");
                    if(ids.size() > 1) {
                        int32 i = ids[0];
                        while(i <= ids[1])
                            parseItemType(i++, element);
                    } else
                        parseItemType(atoi(s.c_str()), element);
                }
            } else {
                std::vector<int32> begin = stdext::split<int32>(element->Attribute("fromid"), ";");
                std::vector<int32> end   = stdext::split<int32>(element->Attribute("toid"), ";");
                if(begin[0] && begin.size() == end.size()) {
                    size_t size = begin.size();
                    for(size_t i = 0; i < size; ++i)
                        while(begin[i] <= end[i])
                            parseItemType(begin[i]++, element);
                }
            }
        }

        doc.Clear();
        m_xmlLoaded = true;
        g_logger.debug("items.xml read successfully.");
    } catch(std::exception& e) {
        g_logger.error(stdext::format("Failed to load '%s' (XML file): %s", file, e.what()));
    }
}
예제 #8
0
bool Recordings::LoadLocations()
{
  std::string url;
  if (Settings::GetInstance().GetRecordingsFromCurrentLocationOnly())
    url = StringUtils::Format("%s%s",  Settings::GetInstance().GetConnectionURL().c_str(), "web/getcurrlocation");
  else
    url = StringUtils::Format("%s%s",  Settings::GetInstance().GetConnectionURL().c_str(), "web/getlocations");

  const std::string strXML = WebUtils::GetHttpXML(url);

  TiXmlDocument xmlDoc;
  if (!xmlDoc.Parse(strXML.c_str()))
  {
    Logger::Log(LEVEL_ERROR, "%s Unable to parse XML: %s at line %d", __FUNCTION__, xmlDoc.ErrorDesc(), xmlDoc.ErrorRow());
    return false;
  }

  TiXmlHandle hDoc(&xmlDoc);

  TiXmlElement* pElem = hDoc.FirstChildElement("e2locations").Element();

  if (!pElem)
  {
    Logger::Log(LEVEL_ERROR, "%s Could not find <e2locations> element", __FUNCTION__);
    return false;
  }

  TiXmlHandle hRoot = TiXmlHandle(pElem);

  TiXmlElement* pNode = hRoot.FirstChildElement("e2location").Element();

  if (!pNode)
  {
    Logger::Log(LEVEL_ERROR, "%s Could not find <e2location> element", __FUNCTION__);
    return false;
  }

  for (; pNode != nullptr; pNode = pNode->NextSiblingElement("e2location"))
  {
    const std::string strTmp = pNode->GetText();

    m_locations.emplace_back(strTmp);

    Logger::Log(LEVEL_DEBUG, "%s Added '%s' as a recording location", __FUNCTION__, strTmp.c_str());
  }

  Logger::Log(LEVEL_INFO, "%s Loaded '%d' recording locations", __FUNCTION__, m_locations.size());

  return true;
}
void LoopbackControllerManager::readUrdf()
{
  std::string urdf_string;

  ros::NodeHandle private_node("~");
  if (private_node.getParam("robot_description", urdf_string))
    ROS_INFO("Loaded robot description from local namespace '%s'.", private_node.getNamespace().c_str());
  else
    rosnode_->getParam("/robot_description", urdf_string);

  // initialize TiXmlDocument doc with a string
  TiXmlDocument doc;
  if (!doc.Parse(urdf_string.c_str()))
  {
    ROS_ERROR("Failed to load robot description");
    abort();
  }

  struct GetActuators : public TiXmlVisitor
  {
    std::set<std::string> actuators;
    virtual bool VisitEnter(const TiXmlElement &elt, const TiXmlAttribute *)
    {
      if (elt.Attribute("name") &&
            ( elt.ValueStr() == std::string("actuator")
           || elt.ValueStr() == std::string("rightActuator")
           || elt.ValueStr() == std::string("leftActuator") )) 
        actuators.insert(elt.Attribute("name"));
      return true;
    }
  } get_actuators;
  doc.RootElement()->Accept(&get_actuators);

  // Places the found actuators into the hardware interface.
  std::set<std::string>::iterator it;
  for (it = get_actuators.actuators.begin(); it != get_actuators.actuators.end(); ++it)
  {
    // ROS_INFO_STREAM("adding actuator " << *it);
    pr2_hardware_interface::Actuator* pr2_actuator = new pr2_hardware_interface::Actuator(*it);
    pr2_actuator->state_.is_enabled_ = true;
    hw_.addActuator(pr2_actuator);
  }

  // Setup mechanism control node
  cm_->initXml(doc.RootElement());

  for (unsigned int i = 0; i < cm_->state_->joint_states_.size(); ++i)
    cm_->state_->joint_states_[i].calibrated_ = true;
}
boost::shared_ptr<MonteEngine> qlMultiAssetCompositeOptionFactory::engine()
{
	TiXmlDocument document;
	document.Parse(paraInfo_.c_str(), 0, TIXML_ENCODING_UTF8);

	TiXmlNode* pricingNode = document.FirstChildElement("pricing");
	FpmlSerialized::Pricing xml_pricing = FpmlSerialized::Pricing(pricingNode);

	Date referenceDate = xml_pricing.getEvaluationTime()->dateValue();
	Settings::instance().evaluationDate() = referenceDate ;

	boost::shared_ptr<FpmlSerialized::Excel_parameter> xml_para = xml_pricing.getExcel_parameter();

	boost::shared_ptr<FpmlSerialized::Excel_standardPara> xml_standard_para = xml_para->getExcel_standardPara();
	
	boost::shared_ptr<FpmlSerialized::Excel_underlyingCalcInfo_para> xml_excelUnderyingCalcInfo_para = xml_standard_para->getExcel_underlyingCalcInfo_para();

	qlProcessFactory process_factory = qlProcessFactory();
	
	//process_factory.setProcessCode(this->underListCode_);
	process_factory.buildProcess(xml_excelUnderyingCalcInfo_para);

	const boost::shared_ptr<ProcessArrayWrapper>& prrArrWrapper
		= process_factory.getProcessArrWrapper();

	qlYieldTermStructureFactory ql_tysf = qlYieldTermStructureFactory();

	//Handle<YieldTermStructure> yieldCurve = factory.yieldTSHandle(pricingParameterNode);
	//boost::shared_ptr<YieldTermStructure> yieldTS = boost::shared_ptr<YieldTermStructure>(
	//				new FlatForward(referenceDate,discount,Actual365Fixed()));

	boost::shared_ptr<FpmlSerialized::Excel_discountCurve_para> xml_discount = xml_standard_para->getExcel_discountCurve_para();

	std::vector<boost::shared_ptr<YieldTermStructure>> yieldTSList
		= ql_tysf.e_yieldTermStructureList(xml_discount);

	//Handle<YieldTermStructure> yieldCurve = Handle<YieldTermStructure>(yieldTS);
	
	boost::shared_ptr<MonteEngine> engine(
								new MonteEngine(this->pricer_,
												prrArrWrapper,
												yieldTSList[0],
												10000,//simulNum
												1));

	

	return engine;
}
예제 #11
0
int TextHandler::convert_word_to_text(const string & filepath, const TextID & tid, const string & file_type, string & text)
{
    string cmd = "java -jar ./mdata/word/WordDocumentExtractor.jar parse -t \"" + file_type + "\" -i \"" + filepath + "\" -m \"" + m_word_workspace + "/" + tid + ".word.tmp\" -x \"" + m_word_workspace + "/"  + tid + ".word.xml\"";
    system(cmd.c_str());

    //读取原文件
    string word_ext_result_file = m_word_workspace + "/" + tid + ".word.xml";
    ByteBuffer data;

    if(false == read_file(word_ext_result_file, data) )
    {
        return ERR_READ_WORD_EXT_FILE_FAILED;
    }

    //解析抽取出的XML
    stringstream ss;

    TiXmlDocument xmldoc;
    xmldoc.Parse(data.String().c_str());
    TiXmlHandle docHandle( &xmldoc );

    try
    {
        size_t idx = 0;
        TiXmlElement * elem = docHandle.FirstChild("document").Child("p", idx).ToElement();

        while(elem)
        {
            const char * tmp = elem->GetText();
            if(tmp)
                ss << tmp << endl;
            else
                ss << endl;

            ++idx;
            elem = docHandle.FirstChild("document").Child("p", idx).ToElement();
        }

    }catch (...)
    {
        return ERR_PARSE_WORD_XML;
    }

    //清理XML资源
    xmldoc.Clear();

    text = ss.str();
    return SUCCESS;
}
예제 #12
0
int DefaultProtocol::ParseCommand(char *content, char *version) {

	TiXmlDocument commands;
	commands.Parse(content);
	TiXmlElement *root_ele = commands.RootElement();
	if (root_ele == NULL) {
		AppLog(APP_LOG_ERR, _T("net: get root element error"));
		return 0;
	}

	int ret = 0;
	//考虑到一个xml可能包括多个method
	for (TiXmlElement *method_ele = root_ele->FirstChildElement("method");
			method_ele; method_ele = method_ele->NextSiblingElement()) {

		TiXmlElement *name_ele = method_ele->FirstChildElement("name");
		if (NULL == name_ele) {
			AppLog(APP_LOG_ERR, _T("net: can not find method name node"));
			continue;
		}

		const char* cmd_id = name_ele->Attribute("id");
		const char* name = name_ele->GetText();
		if	( !name || !cmd_id ) {
			AppLog(APP_LOG_ERR, _T("net: can not find method name value"));
			continue;
		}

		TiXmlElement *params_ele = method_ele->FirstChildElement("params");
		if ( NULL == params_ele ) {
			AppLog(APP_LOG_ERR, _T("net: method:%s parameter is invalid"), name);
			continue;
		}

		CmdMap::iterator cmd = s_cmds.find(name);
		if ( cmd != s_cmds.end() ) {
			cmd->second->Excute(_diplomat, params_ele, version, cmd_id);

		} else {
			AppLog(APP_LOG_DEBUG, _T("net: method no handle :%s"), name);

		}

		ret ++;
	}

	return ret;

}
예제 #13
0
bool CGUIPythonWindowXML::LoadXML(const CStdString &strPath, const CStdString &strLowerPath)
{
  // load our window
  XFILE::CFile file;
  if (!file.Open(strPath) && !file.Open(CStdString(strPath).ToLower()) && !file.Open(strLowerPath))
  {
    // fail - can't load the file
    CLog::Log(LOGERROR, "%s: Unable to load skin file %s", __FUNCTION__, strPath.c_str());
    return false;
  }
  // load the strings in
  unsigned int offset = LoadScriptStrings();

  CStdString xml;
  char *buffer = new char[(unsigned int)file.GetLength()+1];
  if(buffer == NULL)
    return false;
  int size = file.Read(buffer, file.GetLength());
  if (size > 0)
  {
    buffer[size] = 0;
    xml = buffer;
    if (offset)
    {
      // replace the occurences of SCRIPT### with offset+###
      // not particularly efficient, but it works
      int pos = xml.Find("SCRIPT");
      while (pos != (int)CStdString::npos)
      {
        CStdString num = xml.Mid(pos + 6, 4);
        int number = atol(num.c_str());
        CStdString oldNumber, newNumber;
        oldNumber.Format("SCRIPT%d", number);
        newNumber.Format("%lu", offset + number);
        xml.Replace(oldNumber, newNumber);
        pos = xml.Find("SCRIPT", pos + 6);
      }
    }
  }
  delete[] buffer;

  TiXmlDocument xmlDoc;
  xmlDoc.Parse(xml.c_str());

  if (xmlDoc.Error())
    return false;

  return Load(xmlDoc);
}
예제 #14
0
string Versioning::upgradeFrom2To3(string content)
{
    TiXmlDocument doc;
    doc.Parse(content.c_str());
    RRNode node(doc.RootElement());
    node.gotoElement("world");
    node.setAttr("version", "3");

    for (node.gotoElement("rooms")->gotoChild("room"); !node.isNull(); node.gotoNext())
        node.setAttr("bgm", "");

    TiXmlPrinter printer;
    doc.Accept(&printer);
    return printer.CStr();
}
예제 #15
0
int main()
{
    TiXmlDocument xdoc;

    const char * p = xdoc.Parse("<X><Tasks>333</Tasks></X>\n");

    TiXmlElement * root = xdoc.RootElement();


    printf("Element Tasks is expected. Find : %s\n", root->Value());

    printf("P : %p\n", p);

    return 0;
}
예제 #16
0
파일: main.cpp 프로젝트: Sensasion/imguru
std::string getVal(std::string xml, std::string key)
{
	TiXmlDocument doc;
	doc.Parse(xml.c_str());
	
	TiXmlElement* root = doc.RootElement();
	if (root)
	{
		TiXmlElement* child = root->FirstChildElement(key.c_str());
        if (child)
            return child->GetText();
    }
	
	return "";	
}
예제 #17
0
	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());
        }
	}
예제 #18
0
파일: data.cpp 프로젝트: gooddoctor/shylock
data::XML* data::D(engine::String id, engine::String path) {
    if (FILE* file = fopen(path.mb_str(), "r")) {
        fclose(file);
        TiXmlDocument* db = new TiXmlDocument(path.mb_str());
        assert(db->LoadFile());
        return new data::XML(db, id);
    } else {
        TiXmlDocument* db = new TiXmlDocument(path.mb_str());
        db->Parse("<?xml version=\"1.0\" standalone=\"no\" ?>"
                  "<shylock>"
                  "</shylock>");
        assert(db->SaveFile());
        return new data::XML(db, id);
    }
    return 0;
}
예제 #19
0
//---------------------------------------------------------------------------
bool BitmapFont::LoadMetaDataWithTinyXML( ZipFile* zipFile, const char* metaDataFilePath )
{
	if ( !zipFile ) return false;
	size_t fileSize = 0;
	char* fileBuffer = zipFile->LoadFileToHeap( metaDataFilePath, fileSize );
	if ( !fileBuffer ) return false;
	std::string fileBufferAsString( fileBuffer, fileSize );
	TiXmlDocument metaDataDocument;
	metaDataDocument.Parse( fileBufferAsString.c_str(), 0, TIXML_ENCODING_UTF8 );

	if ( !AddTexturesFromZip( metaDataDocument, zipFile, metaDataFilePath ) ) return false;
	ExtractMetaDataFromTinyXMLDocument( metaDataDocument );

	delete fileBuffer;
	return true;
}
예제 #20
0
SocketData* Converter::toSocketData(string data) {

	SocketData* socketData = new SocketData();
	TiXmlDocument xml;
	map<string, string> xmlmap;

	if (xml.Parse(data.c_str()) != 0) {
		const string key = TAG_SOCKETDATA;
		TiXmlElement* socket = xml.FirstChildElement(key.c_str());
		if (socket != NULL) {
			setSocketDataFromClass(socketData, socket, key, socketTagList,
					socketTagListSize);
		}
	}
	return socketData;
}
예제 #21
0
//获取更多游戏
MOREGAME * MyTinyXmlParser::GetMoreGame()
{
    static MOREGAME moreGame[10];
    
    if (!moreGame[0].isUsed) {
        for (int i=0; i<10; i++) {
            moreGame[i].clear();
        }
        
//         CCFileData data(CCFileUtils::fullPathFromRelativePath(MOREGAME_FILE_NAME), "r");
//         unsigned char* pBuffer = data.getBuffer();

		unsigned long  size = 0;
		unsigned char* pBuffer = CCFileUtils::sharedFileUtils()->getFileData(CCFileUtils::sharedFileUtils()->fullPathForFilename( MOREGAME_FILE_NAME).c_str(),"r",&size);
        
        TiXmlDocument* cjDoc = new TiXmlDocument();
        
        cjDoc->Parse((char *)pBuffer);
        
        TiXmlElement* configElement = cjDoc->RootElement();//cjs node
        TiXmlElement* cjElement = configElement->FirstChildElement();//cj node
        
        int index = 0;
        while(cjElement){
            TiXmlElement* idElement = cjElement->FirstChildElement();
            moreGame[index].id = atoi(idElement->GetText());
            
            TiXmlElement* keyElement = idElement->NextSiblingElement();
            strcpy(moreGame[index].name, keyElement->GetText());
            
            TiXmlElement* infoElement = keyElement->NextSiblingElement();
            strcpy(moreGame[index].ico, infoElement->GetText());
            
            TiXmlElement* nameElement = infoElement->NextSiblingElement();
            strcpy(moreGame[index].url, nameElement->GetText());
            
            moreGame[index].isUsed = true;
            
            cjElement = cjElement->NextSiblingElement();
            index++;
        }
        
        delete cjDoc;
    }
    
    return moreGame;
}
예제 #22
0
//#pragma mark ---------------成就处理---------------------
//获取所有成就
CHENGJIU * MyTinyXmlParser::GetChengJiu()
{
    static CHENGJIU ChengJiu[70];
    
    if (!ChengJiu[0].isUsed) {
        for (int i=0; i<70; i++) {
            ChengJiu[i].clear();
        }
        
//         CCFileData data(CCFileUtils::fullPathFromRelativePath(CHENGJIU_FILE_NAME), "r");
//         unsigned char* pBuffer = data.getBuffer();

		unsigned long  size = 0;
		unsigned char* pBuffer = CCFileUtils::sharedFileUtils()->getFileData(CCFileUtils::sharedFileUtils()->fullPathForFilename( CHENGJIU_FILE_NAME).c_str(),"r",&size);
        
        TiXmlDocument* cjDoc = new TiXmlDocument();
        
        cjDoc->Parse((char *)pBuffer);
        
        TiXmlElement* configElement = cjDoc->RootElement();//cjs node
        TiXmlElement* cjElement = configElement->FirstChildElement();//cj node
        
        int index = 0;
        while(cjElement){
            TiXmlElement* idElement = cjElement->FirstChildElement();
            ChengJiu[index].id = atoi(idElement->GetText());
            
            TiXmlElement* keyElement = idElement->NextSiblingElement();
            strcpy(ChengJiu[index].key, keyElement->GetText());
            
            TiXmlElement* infoElement = keyElement->NextSiblingElement();
            strcpy(ChengJiu[index].info, infoElement->GetText());
            
            TiXmlElement* nameElement = infoElement->NextSiblingElement();
            strcpy(ChengJiu[index].name, nameElement->GetText());
            
            ChengJiu[index].isUsed = true;
            
            cjElement = cjElement->NextSiblingElement();
            index++;
        }
        
        delete cjDoc;
    }
    
    return ChengJiu;
}
예제 #23
0
파일: IMDB.cpp 프로젝트: flyingtime/boxee
bool CIMDB::ScrapeFilename(const CStdString& strFileName, CVideoInfoTag& details)
{
  m_parser.m_param[0] = strFileName;

  CUtil::RemoveExtension(m_parser.m_param[0]);
  m_parser.m_param[0].Replace("_"," ");
  CStdString strResult = m_parser.Parse("FileNameScrape",&m_info.settings);
  TiXmlDocument doc;
  doc.Parse(strResult.c_str());
  if (doc.RootElement())
  {
    CNfoFile file;
    if (file.GetDetails(details,strResult.c_str()))
      return true;
  }
  return false;
}
예제 #24
0
bool PackagesInfo::Parse(wxMemoryInputStream& inputStream, muThread_Updater* thread)
{
	m_thread = thread;

	/*wxTextInputStream textStream( inputStream );
	do
	{
		wxString line = textStream.ReadLine();
		wxLogVerbose(line);
	}
	while(textStream.GetChar() != 0);*/

	TiXmlDocument doc;
	doc.Parse(static_cast<char*>(inputStream.GetInputStreamBuffer()->GetBufferStart()));
	TiXmlHandle docHandle( doc.RootElement() );

	// Read format version
	ParseString(docHandle.FirstChild("format").FirstChild("revision").ToElement()).ToLong(&m_fileFormat);

	// Read format compatible
	ParseString(docHandle.FirstChild("format").FirstChild("compatible").ToElement()).ToLong(&m_compatibleFormat);

	// Read update version
	ParseString(docHandle.FirstChild("info").FirstChild("version").ToElement()).ToLong(&m_updateVersion);

	// Read update changelog
	m_changelog = ParseString(docHandle.FirstChild("info").FirstChild("changelog").ToElement());

	// Read packages
	for( TiXmlNode* node = docHandle.FirstChild("package").ToNode(); node; node=node->NextSibling("package") )
	{
		thread->PostProgress(wxT("Package"));
		DownloadInfo info;
		if( info.Parse(node, thread) )
		{
			m_downloads.push_back(info);
			thread->PostProgress(wxT("Package parsed."));
		}
		else
		{
			thread->PostProgress(wxT("Package FAILED!"));
		}
	}

	return true;
}
예제 #25
0
static TiXmlElement* getXMLNodeForKey(const char* pKey, TiXmlElement** rootNode, TiXmlDocument **doc)
{
	TiXmlElement* curNode = NULL;
	// check the key value
	if (! pKey)
	{
		return NULL;
	}

	do 
	{
		TiXmlDocument* xmlDoc = new TiXmlDocument();
		*doc = xmlDoc;
		CCFileData data(CCUserDefault::sharedUserDefault()->getXMLFilePath().c_str(),"rt");
		const char* pXmlBuffer = (const char*)data.getBuffer();
		if(NULL == pXmlBuffer)
		{
			CCLOG("can not read xml file");
			break;
		}
		xmlDoc->Parse(pXmlBuffer);
		// get root node
		*rootNode = xmlDoc->RootElement();
		if (NULL == *rootNode)
		{
			CCLOG("read root node error");
			break;
		}
		// find the node
		curNode = (*rootNode)->FirstChildElement();
		while (NULL != curNode)
		{
			const char* nodeName = curNode->Value();
			if (!strcmp(nodeName, pKey))
			{
				break;
			}

			curNode = curNode->NextSiblingElement();
		}
	} while (0);

	return curNode;

	
}
예제 #26
0
/* Loads an XmlDocument from a filename.
 * Requires:
 * 	@filename		The xml filename
 * Returns:
 * 	@doc			The xmlDocument or 0 if error
 */
TiXmlDocument *Util::loadXmlDocument(const char *fname)
{
	ASSERT(fname);
	TiXmlDocument   *XMLDoc = 0;

	try
	{
		// Strip the path
		Ogre::String basename, path;
		Ogre::StringUtil::splitFilename(fname, basename, path);

		// we will hardcode the groupName
		Ogre::DataStreamPtr pStream = Ogre::ResourceGroupManager::getSingleton().
			openResource( basename, Ogre::ResourceGroupManager::AUTODETECT_RESOURCE_GROUP_NAME);

		//DataStreamPtr pStream = ResourceGroupManager::getSingleton().
		//    openResource( SceneName, groupName );

		Ogre::String data = pStream->getAsString();

		// Open the .scene File
		XMLDoc = new TiXmlDocument();
		XMLDoc->Parse( data.c_str() );

		pStream->close();
		pStream.setNull();

		if( XMLDoc->Error() )
		{
			//We'll just log, and continue on gracefully
			debug("Couldn't load the %s xml\n", fname);
			delete XMLDoc;
			return 0;
		}
	}
	catch(...)
	{
		//We'll just log, and continue on gracefully
		debug("Error creating TiXmlDocument for %s\n", fname);
		delete XMLDoc;
		return 0;
	}

	// Close the XML File
	return XMLDoc;
}
예제 #27
0
bool CNfoFile::DoScrape(ScraperPtr& scraper)
{
  vector<CStdString> extras;
  extras.push_back(m_doc);
  
  CScraperUrl url;
  CFileCurl http;
  vector<CStdString> xml;
  if (scraper->GetParser().HasFunction("NfoUrl"))
    xml = scraper->Run("NfoUrl",url,http,&extras);

  for (vector<CStdString>::iterator it  = xml.begin();
                                    it != xml.end(); ++it)
  {
    TiXmlDocument doc;
    doc.Parse(it->c_str());

    if (doc.RootElement())
    {
      if (stricmp(doc.RootElement()->Value(),"error")==0)
      {
        CIMDB::ShowErrorDialog(doc.RootElement());
        return false;
      }

      TiXmlElement* pId = doc.FirstChildElement("id");
      if (pId && pId->FirstChild())
        m_strImDbNr = pId->FirstChild()->Value();

      TiXmlElement* url = doc.FirstChildElement("url");
      if (url)
      {
        stringstream str;
        str << *url;
        m_strImDbUrl = str.str();
        SetScraperInfo(scraper);
      }
      else if (strcmp(doc.RootElement()->Value(),"url")==0)
      {
        SetScraperInfo(scraper);
        m_strImDbUrl = *it;
      }
    }
  }
  return true;
}
예제 #28
0
파일: mapio.cpp 프로젝트: kilouco/otclient
void Map::loadSpawns(const std::string &fileName)
{
    if(!m_creatures.isLoaded())
        stdext::throw_exception("cannot load spawns; monsters/nps aren't loaded.");

    TiXmlDocument doc;
    doc.Parse(g_resources.loadFile(fileName).c_str());
    if(doc.Error())
        stdext::throw_exception(stdext::format("cannot load spawns xml file '%s: '%s'", fileName, doc.ErrorDesc()));

    TiXmlElement* root = doc.FirstChildElement();
    if(!root || root->ValueStr() != "spawns")
        stdext::throw_exception("malformed spawns file");

    CreatureTypePtr cType(nullptr);
    for(TiXmlElement* node = root->FirstChildElement(); node; node = node->NextSiblingElement()) {
        if(node->ValueTStr() != "spawn")
            stdext::throw_exception("invalid spawn node");

        Position centerPos = node->readPos("center");
        for(TiXmlElement* cNode = node->FirstChildElement(); cNode; cNode = cNode->NextSiblingElement()) {
            if(cNode->ValueStr() != "monster" && cNode->ValueStr() != "npc")
                stdext::throw_exception(stdext::format("invalid spawn-subnode %s", cNode->ValueStr()));

            std::string cName = cNode->Attribute("name");
            stdext::tolower(cName);
            stdext::trim(cName);

            if (!(cType = m_creatures.getCreature(cName)))
                continue;

            cType->setSpawnTime(cNode->readType<int>("spawntime"));
            CreaturePtr creature(new Creature);
            creature->setOutfit(cType->getOutfit());

            stdext::ucwords(cName);
            creature->setName(cName);

            centerPos.x += cNode->readType<int>("x");
            centerPos.y += cNode->readType<int>("y");
            centerPos.z  = cNode->readType<int>("z");

            addThing(creature, centerPos, 4);
        }
    }
}
예제 #29
0
TinyXMLDocument::TinyXMLDocument(CImagesetXMLHandler& handler, const std::string& filename, const std::string& schemaName)
{
	d_handler = &handler;

	char* pDataBuf = 0;
	try {
		// open file
		FILE* fp = fopen(filename.c_str(), "rb");
		if(!fp)
		{
			char szException[MAX_PATH] = {0};
			_snprintf(szException, MAX_PATH, 
				"TinyXMLDocument:Load file %s error",
				filename.c_str());
			throw std::exception(szException);
		}

		fseek(fp, 0, SEEK_END);
		int nFileSize = ftell(fp);
		fseek(fp, 0, SEEK_SET);

		// load file data
		pDataBuf = new char[nFileSize+1];
		memset(pDataBuf, 0, nFileSize+1);
		fread(pDataBuf, 1, nFileSize, fp);
		pDataBuf[nFileSize] = 0;
		fclose(fp);

		TiXmlDocument doc;
		doc.Parse((const char*)pDataBuf);

		const TiXmlElement* currElement = doc.RootElement();

		if (currElement)
		{
			// function called recursively to parse xml data
			processElement(currElement);
		}
	}catch(...)
	{
		delete[] pDataBuf;	pDataBuf = 0;
		throw;
	}

	delete[] pDataBuf;	pDataBuf = 0;
}
예제 #30
0
파일: JSpline.cpp 프로젝트: DrakonPL/jge
bool JSpline::Load(const char *filename, float xscale, float yscale)
{
	JFileSystem *fileSystem = JFileSystem::GetInstance();

	if (fileSystem == NULL) return false;
	if (!fileSystem->OpenFile(filename)) return false;

	int size = fileSystem->GetFileSize();
	char *xmlBuffer = new char[size];
	fileSystem->ReadFile(xmlBuffer, size);

	TiXmlDocument doc;
	doc.Parse(xmlBuffer);

	mCount = 0;

	mMidPoints.clear();
	mPixels.clear();


	TiXmlNode* node = 0;
	//TiXmlElement* todoElement = 0;
	TiXmlElement* element;

	node = doc.RootElement();

	float xx, yy;

	for(element = node->FirstChildElement(); element; element = element->NextSiblingElement())
	{
		xx = 0.0f;
		yy = 0.0f;
		element->QueryFloatAttribute("x", &xx);
		element->QueryFloatAttribute("y", &yy);

		Point pt(xx*xscale, yy*yscale);
		AddControlPoint(pt);
		
	}

	fileSystem->CloseFile();
	delete[] xmlBuffer;

	return true;
}