Example #1
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;
}
bool wxsToolBarItem::OnXmlRead(TiXmlElement* Element,bool IsXRC,bool IsExtra)
{
    bool Ret = wxsParent::OnXmlRead(Element,IsXRC,IsExtra);

    if ( IsXRC )
    {
        wxString Class = cbC2U(Element->Attribute("class"));
        if ( Class == _T("separator") )
        {
            m_Type = Separator;
        }
        else
        {
            // This will handle both wxMenu and wxToolBarItem
            TiXmlElement* Node = Element->FirstChildElement("radio");
            if ( Node && (cbC2U(Node->GetText())==_T("1")) )
            {
                m_Type = Radio;
            }
            else if ( (Node = Element->FirstChildElement("check")) &&
                      (cbC2U(Node->GetText())==_T("1")) )
            {
                m_Type = Check;
            }
            else
            {
                m_Type = Normal;
            }
        }
    }

    return Ret;
}
void XMLConfigReader::getAdaptersFromXML(TiXmlElement* ruleEngineElm, RuleEngine *engine) {
	for (TiXmlElement* adapterElm = ruleEngineElm->FirstChildElement("adapter");
			adapterElm != NULL; adapterElm = adapterElm->NextSiblingElement("adapter")) {
		TiXmlElement* conditionElm = adapterElm->FirstChildElement("rule");
		if(conditionElm != NULL){
			std::string rule = std::string(conditionElm->GetText());
			int delimiterLoc = rule.find(":");
			Adapter *adapter = new Adapter(new Rule(rule.substr(0, delimiterLoc),
					rule.substr(delimiterLoc + 1, rule.length()).at(0)));
			for (TiXmlElement* actionElm = adapterElm->FirstChildElement("action");
					actionElm != NULL; actionElm = actionElm->NextSiblingElement("action")) {
				std::string actionTxt = std::string(actionElm->GetText());
				if(actionTxt == "ADD"){
					adapter->addAction(ADD);
				} else if(actionTxt == "DEL"){
					adapter->addAction(DEL);
				} else if(actionTxt == "MOD"){
					adapter->addAction(MOD);
				} else if(actionTxt == "SHF"){
					adapter->addAction(SHF);
				} else {
					std::cerr << "Action: " << actionTxt << " not defined!!" << std::endl;
				}
			}
			engine->addAdapter(adapter);
		}
	}
}
Example #4
0
void Moteur::chargerXML(TiXmlElement* pModuleXML)
{
    message = "debut";
    trace->print(src,cl,"chargerXML",message);
    Effecteur::chargerXML(pModuleXML);

    TiXmlElement* pElt;
    TiXmlHandle handleModule(0);
    handleModule = TiXmlHandle(pModuleXML);

    pElt = handleModule.FirstChild("coeffRedErreur").Element();
    istringstream iss( pElt->GetText() );
    iss >> coeffRedErreur;
    message = "coeffRedErreur : " + iss.str();
    trace->print(src,cl,"chargerXML",message);

    pElt = handleModule.FirstChild("coeffSatAccelRot_rad_par_s").Element();
    istringstream iss2( pElt->GetText() );
    iss2 >> coeffSatAccelRot_rad_par_s;
    message = "coeffSatAccelRot_rad_par_s : " + iss2.str();
    trace->print(src,cl,"chargerXML",message);

    message = "fin";
    trace->print(src,cl,"chargerXML",message);
}
Example #5
0
void GUI_Button::readAttributes(TiXmlElement* p_element)
{
	TiXmlElement* e = p_element->FirstChildElement("Title");
	if(e)
	{
		const char* p_title = e->GetText();
		setTitle(p_title ? p_title : "");
	}

	e = p_element->FirstChildElement("Image");
	if(e)
	{
		const char* p_imageFilename = e->GetText();
		if(p_imageFilename) setImageFilename(localizeString(p_imageFilename));

		e->QueryIntAttribute("u", &positionOnTexture.x);
		e->QueryIntAttribute("v", &positionOnTexture.y);

		e->QueryIntAttribute("u2", &clickedPositionOnTexture.x);
		e->QueryIntAttribute("v2", &clickedPositionOnTexture.y);
	}

	e = p_element->FirstChildElement("ExtendedStyle");
	if(e) style = 1;
}
Example #6
0
void LoadMetadataV1(TiXmlElement *meta, Metadata *md)
{
  TiXmlElement *node = meta->FirstChildElement("description");

  if(node) {
    if(const char *rtf = node->GetText())
      md->setAbout(rtf);
  }

  node = meta->FirstChildElement("link");

  while(node) {
    const char *rel = node->Attribute("rel");
    const char *url = node->Attribute("href");
    const char *name = node->GetText();

    if(!rel) rel = "";
    if(!name) {
      if(!url) url = "";
      name = url;
    }
    else if(!url) url = name;

    md->addLink(Metadata::getLinkType(rel), {name, url});

    node = node->NextSiblingElement("link");
  }
}
Example #7
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;
}
void mitk::CameraIntrinsics::FromGMLCalibrationXML(TiXmlElement* elem)
{
  assert( elem );
  assert( elem->ValueStr() == "results" );
  cv::Mat CameraMatrix = cv::Mat::zeros(3, 3, cv::DataType<double>::type);
  CameraMatrix.at<double>(2,2) = 1.0;
  cv::Mat DistorsionCoeffs = cv::Mat::zeros(1, 5, cv::DataType<double>::type);

  TiXmlElement* focus_lenXElem = elem->FirstChildElement("focus_lenX");
  endoAssert( focus_lenXElem != 0 );
  CameraMatrix.at<double>(0,0) = atof( focus_lenXElem->GetText() );

  TiXmlElement* focus_lenYElem = elem->FirstChildElement("focus_lenY");
  endoAssert( focus_lenYElem != 0 );
  CameraMatrix.at<double>(1,1) = atof( focus_lenYElem->GetText() );

  TiXmlElement* PrincipalXElem = elem->FirstChildElement("PrincipalX");
  endoAssert( PrincipalXElem != 0 );
  CameraMatrix.at<double>(0,2) = atof( PrincipalXElem->GetText() );

  TiXmlElement* PrincipalYElem = elem->FirstChildElement("PrincipalY");
  endoAssert( PrincipalYElem != 0 );
  CameraMatrix.at<double>(1,2) = atof( PrincipalYElem->GetText() );

  // DISTORSION COEFFS

  TiXmlElement* Dist1Elem = elem->FirstChildElement("Dist1");
  endoAssert( Dist1Elem != 0 );
  DistorsionCoeffs.at<double>(0,0) = atof( Dist1Elem->GetText() );

  TiXmlElement* Dist2Elem = elem->FirstChildElement("Dist2");
  endoAssert( Dist2Elem != 0 );
  DistorsionCoeffs.at<double>(0,1) = atof( Dist2Elem->GetText() );

  TiXmlElement* Dist3Elem = elem->FirstChildElement("Dist3");
  endoAssert( Dist3Elem != 0 );
  DistorsionCoeffs.at<double>(0,2) = atof( Dist3Elem->GetText() );

  TiXmlElement* Dist4Elem = elem->FirstChildElement("Dist4");
  endoAssert( Dist4Elem != 0 );
  DistorsionCoeffs.at<double>(0,3) = atof( Dist4Elem->GetText() );

  int valid = 0;
  elem->QueryIntAttribute("Valid", &valid);

  {
    itk::MutexLockHolder<itk::FastMutexLock> lock(*m_Mutex);
    m_Valid = static_cast<bool>(valid);
    m_CameraMatrix = CameraMatrix;
    m_DistorsionCoeffs = DistorsionCoeffs;
  }

  this->Modified();
}
Example #9
0
void KeyState::deserialize(const string& xml)
{
	string name;
	bool isDown;
	bool isAltDown;
	Log& log = Log::instance();
	istringstream iss(xml);
	TiXmlDocument doc;
	iss >> doc;
	TiXmlHandle docHandle(&doc);
	TiXmlHandle root(NULL);
	TiXmlElement* element;
	element = docHandle.FirstChildElement().Element();
	if(!element)
	{
		log << "KeyState::parseXml(const string&) could not find XML command element\n";
		return;
	}
	root = TiXmlHandle(element);
	element = root.FirstChildElement("name").Element();
	if(!element)
	{
		log << "KeyState::parseXml(const string&) could not find XML name element\n";
		return;
	}
	name = element->GetText();
	element = root.FirstChildElement("isDown").Element();
	if(!element)
	{
		log << "KeyState::parseXml(const string&) could not find XML isDown element\n";
		return;
	}
	isDown = string(element->GetText()).compare("true") == 0;
	element = root.FirstChildElement("isAltDown").Element();
	if(!element)
	{
		log << "KeyState::parseXml(const string&) could not find XML isAltDown element\n";
		return;
	}
	isAltDown = string(element->GetText()).compare("true") == 0;
	if(name.compare("moveForward") == 0)
		up = isDown;
	else if(name.compare("moveBackward") == 0)
		down = isDown;
	else if(name.compare("moveLeft") == 0)
		left = isDown;
	else if(name.compare("moveRight") == 0)
		right = isDown;
	else if(name.compare("fire") == 0)
		fire = isDown;
}
Example #10
0
void GPUImageFilter::parseXML(const char* fname) {
    //load filter description file
    printf("Loading Filter...\n");


    //load and parse xml filter description file
    TiXmlDocument doc(ofToDataPath(fname).c_str());
    if (!doc.LoadFile()) printf("error loading filter description file");


    //get the name of the filter
    TiXmlElement* root_node = doc.RootElement();

    this->name = root_node->Attribute("name");

    printf("Filter Name:%s\n", this->name);


    //get the  shader source file names
    TiXmlElement* node = root_node;

    node = root_node->FirstChildElement("VertexShader");
    const char* vertSrc = node ? node->GetText() : NULL;

    node = root_node->FirstChildElement("GeometryShader");
    const char* geomSrc = node ? node->GetText() : NULL;
    if (geomSrc != NULL) { //We are using a geometry shader
        this->useGeometryShader = true;
    }

    node = root_node->FirstChildElement("FragmentShader");
    const char* fragSrc = node ? node->GetText() : NULL;

    this->shader = new ShaderProgram(vertSrc, geomSrc, ofToDataPath(fragSrc).c_str());


    //get parameters
    //TODO: add type handling
    while( (node = (TiXmlElement*)node->NextSibling("Parameter")) ) {
        const char* name = node->Attribute("name");
        float type = atof(node->Attribute("type"));
        float min = atof(node->Attribute("min"));
        float max = atof(node->Attribute("max"));
        float val = atof(node->GetText());


        parameters["size_cx"] = new FilterParameter("size_cx", (float)res_x, 0, 0, 0 );
        parameters["size_cy"] = new FilterParameter("size_cy", (float)res_y, 0, 0, 0 );
        parameters[std::string(name)] = new FilterParameter(name, val, min, max, (int)type );
    }
}
Example #11
0
bool wxsMenuItem::OnXmlRead(TiXmlElement* Element,bool IsXRC,bool IsExtra)
{
    bool Ret = wxsParent::OnXmlRead(Element,IsXRC,IsExtra);

    if ( IsXRC )
    {
        wxString Class = cbC2U(Element->Attribute("class"));
        if ( Class == _T("separator") )
        {
            m_Type = Separator;
        }
        else if ( Class == _T("break") )
        {
            m_Type = Break;
        }
        else
        {
            // This will handle both wxMenu and wxMenuItem
            TiXmlElement* Node = Element->FirstChildElement("radio");
            if ( Node && (cbC2U(Node->GetText())==_T("1")) )
            {
                m_Type = Radio;
            }
            else
            {
                Node = Element->FirstChildElement("checkable");

                // Backward BUG-compatibility
                if ( !Node ) Node = Element->FirstChildElement("check");

                if ( Node && (cbC2U(Node->GetText())==_T("1")) )
                {
                    m_Type = Check;
                    // Now, we are going to check its state, either checked or not checked
                    TiXmlElement* checkedNode = Element->FirstChildElement("checked");
                    if (checkedNode && (cbC2U(checkedNode->GetText())==_T("1")))
                        m_Checked = true;
                    // otherwise, the m_Checked will default to false.
                }
                else
                {
                    m_Type = Normal;
                }
            }
        }
    }

    return Ret;
}
Example #12
0
char* CXmlOpeation::GetData_Text(const char* pName, TiXmlElement*& pNextTiXmlElement)
{
	if(m_pRootElement == NULL)
	{
		return NULL;
	}

	TiXmlElement* pTiXmlElement = NULL;
	if(NULL == pNextTiXmlElement)
	{
		pTiXmlElement = m_pRootElement->FirstChildElement(pName);
		pNextTiXmlElement = pTiXmlElement;
	}
	else
	{
		pTiXmlElement  = pNextTiXmlElement->NextSiblingElement();
		pNextTiXmlElement = pTiXmlElement;
	}

	if(NULL != pTiXmlElement)
	{
		return (char* )pTiXmlElement->GetText();
	}

	return NULL;
}
Example #13
0
bool CFanart::Unpack()
{
    TiXmlDocument doc;
    doc.Parse(m_xml.c_str());

    m_fanart.clear();
    m_url.Empty();

    TiXmlElement *fanart = doc.FirstChildElement("fanart");
    if (fanart)
    {
        m_url = fanart->Attribute("url");
        TiXmlElement *fanartThumb = fanart->FirstChildElement("thumb");
        while (fanartThumb)
        {
            SFanartData data;
            data.strImage = fanartThumb->GetText();
            data.strResolution = fanartThumb->Attribute("dim");
            data.strPreview = fanartThumb->Attribute("preview");
            if (data.strPreview.IsEmpty())
            {   // could be due to an old version in db - use old hardcoded method for now
                if (m_url.Equals("http://thetvdb.com/banners/"))
                    data.strPreview = "_cache/" + data.strImage;
            }
            ParseColors(fanartThumb->Attribute("colors"), data.strColors);
            m_fanart.push_back(data);
            fanartThumb = fanartThumb->NextSiblingElement("thumb");
        }
    }
    return true;
}
Example #14
0
TileMap tilemapFromXML(TiXmlDocument* doc) {
	TileMap tilemap;
	
	// Get top level attributes for source tilemap
	TiXmlElement* tilemapElement = doc->FirstChild()->ToElement();
//	int totalWidth, totalHeight, inputTileWidth, inputTileHeight;
	assert(TIXML_SUCCESS == tilemapElement->QueryIntAttribute("width", &tilemap.totalWidth));
	assert(TIXML_SUCCESS == tilemapElement->QueryIntAttribute("height", &tilemap.totalHeight));
	assert(TIXML_SUCCESS == tilemapElement->QueryIntAttribute("tileWidth", &tilemap.tileWidth));
	assert(TIXML_SUCCESS == tilemapElement->QueryIntAttribute("tileHeight", &tilemap.tileHeight));
	
	tilemap.highestIndex = 0;
	
	// CREATE ORIGINAL TILEMAP (and find number of atlases)
	for (TiXmlNode* child = doc->FirstChild()->FirstChild(); child != 0; child = child->NextSibling()) {
		TiXmlElement* element = child->ToElement();
		
		if(0 == strcmp(element->Value(), "row")) {
			string rowText = element->GetText();
			vector<int> inputRow = parseRow(rowText);
			tilemap.tilemap.push_back(inputRow);
		}
		else if(0 == strcmp(element->Value(), "atlas")) {
			int atlasWidth, atlasHeight;
			
			assert(TIXML_SUCCESS == element->QueryIntAttribute("width", &atlasWidth));
			assert(TIXML_SUCCESS == element->QueryIntAttribute("height", &atlasHeight));
			
			tilemap.highestIndex += (atlasWidth / tilemap.tileWidth) * (atlasHeight / tilemap.tileHeight);
		}
	}
	
	return tilemap;
}
Example #15
0
std::list<wxString> CThemeProvider::GetThemeSizes(const wxString& themePath)
{
	std::list<wxString> sizes;

	wxFileName fn(wxGetApp().GetResourceDir() + themePath, _T("theme.xml"));
	TiXmlElement* pDocument = GetXmlFile(fn.GetFullPath(), false);
	if (!pDocument)
		return sizes;

	TiXmlElement* pTheme = pDocument->FirstChildElement("Theme");
	if (pTheme)
	{
		for (TiXmlElement* pSize = pTheme->FirstChildElement("size"); pSize; pSize = pSize->NextSiblingElement("size"))
		{
			const char* txt = pSize->GetText();
			if (!txt)
				continue;

			wxString size = ConvLocal(txt);
			if (size == _T(""))
				continue;

			sizes.push_back(size);
		}
	}

	delete pDocument->GetDocument();

	return sizes;
}
Example #16
0
bool CThemeProvider::ThemeHasSize(const wxString& themePath, const wxString& size)
{
	wxFileName fn(wxGetApp().GetResourceDir() + themePath, _T("theme.xml"));
	TiXmlElement* pDocument = GetXmlFile(fn.GetFullPath(), false);
	if (!pDocument)
		return false;

	TiXmlElement* pTheme = pDocument->FirstChildElement("Theme");

	if (!pTheme)
	{
		delete pDocument->GetDocument();
		return false;
	}

	for (TiXmlElement* pSize = pTheme->FirstChildElement("size"); pSize; pSize = pSize->NextSiblingElement("size"))
	{
		const char* txt = pSize->GetText();
		if (!txt)
			continue;

		if (size == ConvLocal(txt))
		{
			delete pDocument->GetDocument();
			return true;
		}
	}

	delete pDocument->GetDocument();

	return false;
}
Example #17
0
void LoadVersionV1(TiXmlElement *verNode, Package *pkg)
{
  const char *name = verNode->Attribute("name");
  if(!name) name = "";

  Version *ver = new Version(name, pkg);
  unique_ptr<Version> ptr(ver);

  const char *author = verNode->Attribute("author");
  if(author) ver->setAuthor(author);

  const char *time = verNode->Attribute("time");
  if(time) ver->setTime(time);

  TiXmlElement *node = verNode->FirstChildElement("source");

  while(node) {
    LoadSourceV1(node, ver);
    node = node->NextSiblingElement("source");
  }

  node = verNode->FirstChildElement("changelog");

  if(node) {
    if(const char *changelog = node->GetText())
      ver->setChangelog(changelog);
  }

  if(pkg->addVersion(ver))
    ptr.release();
}
Example #18
0
bool CGameWorld::initNet(TiXmlElement* pRoot)
{
	CORE("init:","initNet..");
	g_cfg.client_listen_ip = "localhost";
	g_cfg.client_listen_port = 0;//8888;
	g_cfg.unlogin_timeout = 60;
	g_cfg.local_login = true;
	g_cfg.c2r_interval = 500;
	g_cfg.r2c_interval = 250;
	g_cfg.cl_pre_buffer = 3;
	g_cfg.cl_max_buffer = 1;

	//read config
	CORE("init:","initNet read config..");
	if(!pRoot)
		return false;
	m_strListenIp="0.0.0.0";
	TiXmlElement* pEleCon = pRoot->FirstChildElement("ip");
	if (pEleCon)
	{
		m_strListenIp = pEleCon->GetText();
	}
	string strport="7200";
	TiXmlElement* pEleConPort = pRoot->FirstChildElement("port");
	if (pEleConPort)
	{
		strport = pEleConPort->GetText();
	}
	m_iListenPort = atol(strport.c_str());

	g_cfg.client_listen_ip = m_strListenIp;
	g_cfg.client_listen_port = m_iListenPort;
	//start listen
	CORE("init:","start listen(%s,%d)..",m_strListenIp.c_str(),m_iListenPort);
	if(!m_ClientListener.StartListen(m_strListenIp.c_str(),
		m_iListenPort,true))
	{
		CORE("¼àÌý¶Ë¿Úʧ°Ü: ","start listen ip=%s,port = %d",m_strListenIp.c_str(),m_iListenPort);
		return false;
	}
	else
	{
		CORE("¿ªÊ¼¼àÌý¶Ë¿Ú: ","start listen  ip=%s,port = %d",m_strListenIp.c_str(),m_iListenPort);
	}
	InitChannel();
	return true;
}
void XMLConfigReader::getRulesFromXML(TiXmlElement* ruleEngineElm, RuleEngine* engine) {
	for (TiXmlElement* ruleElm = ruleEngineElm->FirstChildElement("rule");
			ruleElm != NULL; ruleElm = ruleElm->NextSiblingElement("rule")) {
		std::string rule = std::string(ruleElm->GetText());
		int delimiterLoc = rule.find(":");
		engine->addRule(new Rule(rule.substr(0, delimiterLoc),
				rule.substr(delimiterLoc + 1, rule.length()).at(0)));
	}
}
void CDeicingAndAnticingsXMLGenerator::AddPrecipitationType(TiXmlElement* _element,CPrecipitationtype* _type)
{
	if(_element == NULL || _type == NULL)
		return ;
	TiXmlElement* holdEle  = _element->FirstChildElement(_T("HoldoverTime")) ;
	_type->SetHoldOverTime( (float)atof(holdEle->GetText()) ) ;

	holdEle = _element->FirstChildElement(_T("InspectionTime")) ;
	CProbDistEntry* pdx = GetProcdisIndex(holdEle->GetText()) ;
	if(pdx != NULL)
	{
	  _type->GetInspection()->SetProDistrubution(pdx) ;
	  _type->GetInspection()->SaveData() ;
	}
	holdEle = _element->FirstChildElement(_T("De-icefluid")) ;
	_type->SetDeIceTime((float)atof(holdEle->GetText())) ;

	holdEle = _element->FirstChildElement(_T("Anti-icefluid")) ;
	_type->SetAntiIceTime((float)atof(holdEle->GetText())) ;
}
Example #21
0
std::string imageIdFromXml(std::string xml, std::string& err)
{
	TiXmlDocument doc;
	doc.Parse(xml.c_str());
	
	TiXmlElement* root = doc.RootElement();
	if (root)
	{
		TiXmlElement* id = root->FirstChildElement("id");
        if (id)
            return id->GetText();
        
        TiXmlElement* error = root->FirstChildElement("error");
        if (error)
            return error->GetText();
	}
	
	return "";

}
Example #22
0
//takes the current <ar> node pointer and gets the word and definition for it
//Then moves the pointer on to the next <ar> node (or 'end' if no more found)
//
//Note, I find the formatting of the definition within the node bizzarre as the
//definition can be split into several blocks, with nodes embedded with the text.
//Not the way I'd define a dictionary schema, but hey, its free and comprehensive
//so I can't really complain.
TiXmlElement* Words2::xdxfNextWord(TiXmlElement* ar, std::string &word, std::string &def)
{
	if (!_doc) return 0;

	TiXmlElement *tmpElement;
	TiXmlText *tmpText;

	TiXmlNode *child = 0;
	for( child = ar->FirstChild(); child; child = child->NextSibling() )
	{
//		std::string text = child->Value();
//		std::cout << "<k>" << text.c_str() << "</k> : " << std::endl;

		if (child->Type() == TiXmlNode::ELEMENT)
		{
			tmpElement = child->ToElement();
			if (tmpElement->ValueStr() == "k")
			{
				++_countXdxfWords;
				word = tmpElement->GetText();	//get the <k>WORD</k>
				pptxt::makeUpper(word);			//force to UPPER case (def tests against it, below)
			}
			//else ignore; dont care about <b> or <c> etc
		}
		else if (word.length() && child->Type() == TiXmlNode::TEXT)
		{
			tmpText = child->ToText();
			def = tmpText->Value();	//get the text (NOT in a <></> tag, wtf?

			//check if the def starts with the dictionary word.
			//Some xdxf dictionary defs I've seen do something like:
			//"abbacy n : the jurisdiction or office of an abbot"
			//where the "abbacy " part is not required for the game,
			//as it's already shown so try and remove it.
			std::string::size_type pos = def.find_first_of(" ");
			std::string prefix = def.substr(0,pos);	//may contain other chars, if so those words will stay
			pptxt::makeUpper(prefix);
			if (word == prefix)
				def = def.substr(pos);

			if (def.length() > MAX_REWORD_DESCRIPTION)
			{
				def.erase(MAX_REWORD_DESCRIPTION);
				def += "...";	//indicate it was cut short
			}
//			std::cout << word.c_str() << " - def: " << tmpstr << std::endl;

			break;	//out of for child loop as we now want next <ar> word and its def
		}
	}

	return ar->NextSiblingElement("ar");
}
Example #23
0
bool OUGUILable::OnLoadFromXml(TiXmlElement* pElement, OUGUIObject* pWillParent)
{
    OUGUIObject::OnLoadFromXml(pElement, pWillParent);

    TiXmlElement* pNode;
    for(pNode = pElement->FirstChildElement(); pNode != NULL; pNode = pNode->NextSiblingElement())
    {
        Assert(pNode->Value(), "Empty node value.");
        OUStringFunc str = pNode->Value();
        str.ToUppercase();

        if(str.GetString() == "TOP")
        {
            m_ptPos.m_fY = atoi(pNode->GetText());
        }
        else
        if(str.GetString() == "LEFT")
        {
            m_ptPos.m_fX = atoi(pNode->GetText());
        }
        else
        if(str.GetString() == "FONT")
        {
            SetFontname(pNode->GetText());
        }
        else
        if(str.GetString() == "TEXT")
        {
            SetText(pNode->GetText());
        }
        else
        if(str.GetString() == "COLOR")
        {
            SetColor(pNode->GetText());
        }
    }

    m_bInited = true;
    return true;
}
Example #24
0
void SPDImplementation::parseCode(TiXmlElement *elem)
{
    DEBUG(4, SPDImplementation, "In parse Code.");

    TiXmlElement *code = elem->FirstChildElement("code");
    setCodeType (code->Attribute("type"));

    TiXmlElement *local = code->FirstChildElement("localfile");
    codeFile = local->Attribute("name");

    TiXmlElement *entry = elem->FirstChildElement("entrypoint");
    if (entry)
        entryPoint = entry->GetText();

    TiXmlElement *stack= elem->FirstChildElement("stacksize");
    if (stack)
        stackSize = entry->GetText();

    TiXmlElement *prio = elem->FirstChildElement("priority");
    if (prio)
        priority = entry->GetText();
}
       XsdTypeToken(TiXmlNode* xmlNode)
       : ISerialized(xmlNode){
             TiXmlElement* xmlElem = xmlNode->ToElement();
             const char *pKey = xmlElem->Value();
             const char *pText = xmlElem->GetText();

             if( pText ) { this->valueStr = pText; }
             else if( xmlElem->NoChildren() ) { this->valueStr = "NULL ( empty value )"; }
             else { this->valueStr = "NULL value ( Node has Children )"; }
             #ifdef ConsolePrint
                FileManager::instance().outFile_ << FileManager::instance().tap_.c_str() << "   " << xmlNode->Value() << " : " << this->valueStr.c_str() << std::endl;
             #endif
       }
Example #26
0
RobotInterface::ParamList RobotInterface::XMLReader::Private::readParamListTag(TiXmlElement* paramListElem)
{
    if (paramListElem->ValueStr().compare("paramlist") != 0) {
        SYNTAX_ERROR(paramListElem->Row()) << "Expected \"paramlist\". Found" << paramListElem->ValueStr();
    }

    ParamList params;
    Param mainparam;

    if (paramListElem->QueryStringAttribute("name", &mainparam.name()) != TIXML_SUCCESS) {
        SYNTAX_ERROR(paramListElem->Row()) << "\"paramlist\" element should contain the \"name\" attribute";
    }

    params.push_back(mainparam);

    // yDebug() << "Found paramlist [" << params.at(0).name() << "]";

    for (TiXmlElement* childElem = paramListElem->FirstChildElement(); childElem != 0; childElem = childElem->NextSiblingElement()) {
        if (childElem->ValueStr().compare("elem") != 0) {
            SYNTAX_ERROR(childElem->Row()) << "Expected \"elem\". Found" << childElem->ValueStr();
        }

        Param childParam;

        if (childElem->QueryStringAttribute("name", &childParam.name()) != TIXML_SUCCESS) {
            SYNTAX_ERROR(childElem->Row()) << "\"elem\" element should contain the \"name\" attribute";
        }

        const char *valueText = childElem->GetText();
        if (!valueText) {
            SYNTAX_ERROR(childElem->Row()) << "\"elem\" element should have a value [ \"name\" = " << childParam.name() << "]";
        }
        childParam.value() = valueText;

        params.push_back(childParam);
    }

    if (params.empty()) {
        SYNTAX_ERROR(paramListElem->Row()) << "\"paramlist\" cannot be empty";
    }

    // +1 skips the first element, that is the main param
    for (ParamList::iterator it = params.begin() + 1; it != params.end(); ++it) {
        Param &param = *it;
        params.at(0).value() += (params.at(0).value().empty() ? "(" : " ") + param.name();
    }
    params.at(0).value() += ")";

    // yDebug() << params;
    return params;
}
Example #27
0
		Common::Xml::Node Xml::GetRootNode(){
			if(m_pDocument!=NULL){
	#ifdef	_DEBUG
				TiXmlElement*	p	=	m_pDocument->RootElement();
				if(p!=NULL){
					OutputDebugStringA(p->GetText());
					OutputDebugStringA(p->Value());
					OutputDebugStringA("\n");
				}
	#endif
				return	Node(m_pDocument->RootElement());
			}
			return	Node();
		}
Example #28
0
bool SData::LoadCache()
{
  XBMC->Log(LOG_DEBUG, "%s", __FUNCTION__);

  std::string strCacheFile;
  TiXmlDocument doc;
  TiXmlElement *pRootElement = NULL;
  TiXmlElement *pTokenElement = NULL;

  strCacheFile = Utils::GetFilePath("cache.xml");

  if (!doc.LoadFile(strCacheFile)) {
    XBMC->Log(LOG_ERROR, "%s: failed to load: \"%s\"", __FUNCTION__, strCacheFile.c_str());
    return false;
  }

  pRootElement = doc.RootElement();
  if (strcmp(pRootElement->Value(), "cache") != 0) {
    XBMC->Log(LOG_ERROR, "%s: invalid xml doc. root element 'cache' not found", __FUNCTION__);
    return false;
  }

  if (!m_bTokenManuallySet) {
    pTokenElement = pRootElement->FirstChildElement("token");
    if (!pTokenElement || !pTokenElement->GetText()) {
      XBMC->Log(LOG_DEBUG, "%s: 'token' element not found", __FUNCTION__);
    } else {
      SC_STR_SET(m_identity.token, pTokenElement->GetText());
    }

    XBMC->Log(LOG_DEBUG, "%s: token=%s", __FUNCTION__, m_identity.token);
  }

  doc.Clear();

  return true;
}
Example #29
0
int parse_rotation_info(struct parameter_struct *parameters,TiXmlHandle *docHandle){
	PetscErrorCode ierr;
	//section to read in product wavefunction over lap details
	TiXmlElement* element = docHandle->FirstChild( "SIMULATION" ).FirstChild( "PARAMETERS").FirstChild( "SYMMETRIES").FirstChild( "ROTATION").Element();
	if ( element)
	{	
		parameters->use_rotation_invariance = PETSC_TRUE;
		parameters->representative_check = &rotation_representative_check; 
		parameters->group_representative = &rotation_group_representative;
		parameters->group_normal = &rotation_group_normal; 
		parameters->rotation_number_relevant_sectors = -1;

		char buf2[MAX_STRING];
		if ( element->Attribute("file") == NULL ) {
			PetscPrintf(PETSC_COMM_WORLD,"A file must be supplied to describe the rotation when using rotational invariance.\n");
			return 1;
		}
		strcpy(parameters->rotation_info_file,element->Attribute("file"));
		
		element = docHandle->FirstChild( "SIMULATION" ).FirstChild( "PARAMETERS").FirstChild( "SYMMETRIES").FirstChild("ROTATION").FirstChild("RELEVANT_SECTORS").Element();
		if ( element ) {
			if ( element->Attribute("number") == NULL ) {
				PetscPrintf(PETSC_COMM_WORLD,"The number of relevant sectors must be specified.\n");
				return 1;
			}
			parameters->rotation_number_relevant_sectors = atoi(element->Attribute("number"));
			ierr = PetscMalloc(parameters->rotation_number_relevant_sectors*sizeof(PetscInt),&parameters->rotation_relevant_sectors);CHKERRQ(ierr);
			for ( int i = 0 ; i < parameters->rotation_number_relevant_sectors ; i++ ) {
				element = docHandle->FirstChild( "SIMULATION" ).FirstChild( "PARAMETERS").FirstChild( "SYMMETRIES").FirstChild("ROTATION").FirstChild("RELEVANT_SECTORS").Child("SECTOR",i).Element();
				if ( element ) {
					parameters->rotation_relevant_sectors[i] = atoi(element->GetText());
				} else {
					PetscPrintf(PETSC_COMM_WORLD,"Number of relevant rotation sectors incorrect.\n");
					return 1;
				}
			}
			if ( parameters->verbosity >= 3) {
				stringstream ss ;
				ss << "\tNumber of rotation sectors to use: " << parameters->rotation_number_relevant_sectors << " (" ; 
				PetscPrintf(PETSC_COMM_WORLD,"%s",ss.str().c_str());
				for ( int i = 0 ; i < parameters->rotation_number_relevant_sectors ; i++ ) {
					PetscPrintf(PETSC_COMM_WORLD,"%d ", (int)parameters->rotation_relevant_sectors[i]);
				}
				PetscPrintf(PETSC_COMM_WORLD,")\n");
			}
		}	
	}	
	return 0;
}
Example #30
0
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 "";	
}