Пример #1
0
XmlValuePtr XmlReader::operator[] ( const char *name ) const
{
  TiXmlNode *node = pd->doc->FirstChild(name);
  if (node == NULL)
  {
    LOG(ERROR) << "Xml node " << name << " not found";
    return XmlValuePtr(new XmlValue());
  }

  TiXmlElement *element = node->ToElement();
  if (element == NULL)
  {
    LOG(ERROR) << "Xml node " << name
               << " not element, type = " << node->Type();
    return XmlValuePtr(new XmlValue());
  }

  return XmlValuePtr(new XmlNode(element));
}
Пример #2
0
TiXmlNode * FindNextNotOf(TiXmlNode * node, const char * ids[])
{
	if(!node)
		return NULL;
	TiXmlNode * loc;
	int index;
		return false;
	for(loc = node->NextSibling(); loc; loc = loc->NextSibling()) {
		if (loc->Type() == TiXmlNode::COMMENT)
			continue;
		index = 0;
		indexcheck:
		if(NodeIs(loc,ids[index]))
			continue;
		if(ids[++index]) goto indexcheck;
		return loc;
	}
	return NULL;
}
Пример #3
0
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;
}
Пример #4
0
void XCFParser::parsePartition(TiXmlElement* partition){
    TiXmlString partitionId (partition->Attribute(XCFMapping::PARTITION_ID));
    TiXmlNode* node = partition->FirstChild();

    while (node != NULL){
        if (node->Type() == TiXmlNode::TINYXML_ELEMENT) {
            TiXmlElement* element = (TiXmlElement*)node;
            TiXmlString name(node->Value());
            if (name == XCFMapping::INSTANCE) {
                TiXmlString instanceId (element->Attribute(XCFMapping::INSTANCE_ID));
                mapStr->insert(pair<string,string>(instanceId.c_str(), partitionId.c_str()));
            }else {
                cerr << "Invalid node "<< name.c_str() << endl;
                exit(1);
            }
        }

        node = node->NextSibling();
    }
}
Пример #5
0
void loadXmlInto(const std::string& arFileName, IXMLDataBound* sps)
{
	TiXmlDocument doc(arFileName);
	
	if(!doc.LoadFile())
	{
		std::ostringstream oss;
		oss << "Load file failed on: " << arFileName << " - " << doc.ErrorDesc() << " at " << doc.ErrorRow() << ":"<< doc.ErrorCol();
		throw Exception("loadXmlInto", oss.str(),  IXMLDataBound::ERR_XML_NO_FILE);
	}
	if(!doc.Type() == TiXmlNode::DOCUMENT)
		throw Exception("loadXmlInto","Document is not of type TiXmlNode::DOCUMENT");

	TiXmlNode* node = doc.FirstChild();
	TiXmlNode* lastChild = doc.LastChild();
	while(node->Type() != TiXmlNode::ELEMENT && node != lastChild){
		node = node->NextSibling();
	}
	sps->fromXml(node);
};
Пример #6
0
void MainFrame::OfferConfig(TiXmlDocument* config, wxListBox* listbox,
                            std::vector<TiXmlNode*> *nodes)
{
  // put configuration to wxCheckListBox or wxListBox
  nodes->clear();
  listbox->Clear();
  TiXmlElement* cfgroot = config->FirstChildElement("CodeBlocksConfig");

  if (!TiXmlSuccess(config))
    return;

  TiXmlNode* child = NULL;
  for (child = cfgroot->FirstChild(); child; child = child->NextSibling())
  {
    if (child->Type()==TiXmlNode::ELEMENT)
    {
      OfferNode(&child, listbox, nodes);
    }
  }
}// OfferConfig
Пример #7
0
void XmlParser::matNode(TiXmlNode* pParent) {

    TiXmlNode* pChild;
    for (pChild = pParent->FirstChild(); pChild != 0; pChild = pChild->NextSibling()) {
        int t = pChild->Type();
        if (t == TiXmlNode::ELEMENT) {
            string element_value(pChild->Value());
            if (element_value == "macro-xs")
                objects.push_back(macroAttrib(pChild->ToElement()));
            else if (element_value == "material") {
                vector<McObject*> ace_objects = aceAttrib(pChild->ToElement());
                objects.insert(objects.end(), ace_objects.begin(), ace_objects.end());
            } else {
                vector<string> keywords;
                keywords.push_back(element_value);
                throw KeywordParserError("Unrecognized material keyword <" + element_value + ">",keywords);
            }
        }
    }

}
Пример #8
0
void XmlParser::srcNode(TiXmlNode* pParent) {

	TiXmlNode* pChild;
	for (pChild = pParent->FirstChild(); pChild != 0; pChild = pChild->NextSibling()) {
		int t = pChild->Type();
		if (t == TiXmlNode::ELEMENT) {
			string element_value(pChild->Value());
			if (element_value == "dist")
				objects.push_back(distAttrib(pChild->ToElement()));
			else if (element_value == "sampler")
				objects.push_back(samplerAttrib(pChild->ToElement()));
			else if (element_value == "source")
				objects.push_back(sourceAttrib(pChild->ToElement()));
			else {
				vector<string> keywords;
				keywords.push_back(element_value);
				throw KeywordParserError("Unrecognized source keyword <" + element_value + ">",keywords);
			}
		}
	}
}
Пример #9
0
TiXmlText*
PluginXmlParser::requireText (
    const TiXmlElement& elem,
	OsStatus* err)
{
	TiXmlNode* tn = (TiXmlNode*)elem.FirstChild();
	if (tn != NULL && tn->Type() == TiXmlNode::TEXT)
	{
		TiXmlText* t = tn->ToText();
		if (t->Value() != NULL)
		{
			return t;
		}
	}

	OsSysLog::add(FAC_SIP, PRI_ERR, "PluginXmlParser::requiredText "
		 "missing element text body %s ", elem.Value());
	*err = OS_FAILED;

	return NULL;
}
Пример #10
0
unsigned int Handle_t::checksum(unsigned int param, fcn_t fcn) const {
#ifdef DD4HEP_USE_TINYXML
  typedef map<string, string> StringMap;
  TiXmlNode* n = Xml(m_node).n;
  if ( n ) {
    if ( 0 == fcn ) fcn = adler32;
    switch (n->Type()) {
    case TiXmlNode::ELEMENT: {
      map<string,string> m;
      TiXmlElement* e = n->ToElement();
      TiXmlAttribute* p=e->FirstAttribute();
      for(; p; p=p->Next()) m.insert(make_pair(p->Name(),p->Value()));
      param = (*fcn)(param,e->Value(),::strlen(e->Value()));
      for(StringMap::const_iterator i=m.begin();i!=m.end();++i) {
        param = (*fcn)(param,(*i).first.c_str(),(*i).first.length());
        param = (*fcn)(param,(*i).second.c_str(),(*i).second.length());
      }
      break;
    }
    case TiXmlNode::TEXT:
      param = (*fcn)(param,n->ToText()->Value(),::strlen(n->ToText()->Value()));
      break;
    case TiXmlNode::UNKNOWN:
    case TiXmlNode::COMMENT:
    case TiXmlNode::DOCUMENT:
    case TiXmlNode::DECLARATION:
    default:
      break;
    }
    for(TiXmlNode* c=n->FirstChild(); c; c=c->NextSibling())
      param = Handle_t((XmlElement*)c->ToElement()).checksum(param,fcn);
  }
#else
  if ( 0 == fcn ) fcn = adler32;
  if ( 0 == fcn )  {
  }
#endif
  return param;
}
/*
 * TinyXml has loaded and parsed the XML document for us.  We need to
 * run through the DOM tree, pull out the interesting bits, and make
 * sure the stuff we need is present.
 *
 * Returns "true" on success, "false" on failure.
 */
bool PhoneData::ProcessAndValidate(TiXmlDocument* pDoc)
{
    bool deviceFound = false;
    TiXmlNode* pChild;

    assert(pDoc->Type() == TiXmlNode::DOCUMENT);

    for (pChild = pDoc->FirstChild(); pChild != NULL;
        pChild = pChild->NextSibling())
    {
        /*
         * Find the <device> entry.  There should be exactly one.
         */
        if (pChild->Type() == TiXmlNode::ELEMENT) {
            if (strcasecmp(pChild->Value(), "device") != 0) {
                fprintf(stderr,
                    "SimCFG: Warning: unexpected element '%s' at top level\n",
                    pChild->Value());
                continue;
            }
            if (deviceFound) {
                fprintf(stderr, "SimCFG: one <device> per customer\n");
                return false;
            }

            bool result = ProcessDevice(pChild);
            if (!result)
                return false;
            deviceFound = true;
        }
    }

    if (!deviceFound) {
        fprintf(stderr, "SimCFG: no <device> section found\n");
        return false;
    }

    return true;
}
Пример #12
0
void XmlParser::geoNode(TiXmlNode* pParent) {

	TiXmlNode* pChild;
	for (pChild = pParent->FirstChild(); pChild != 0; pChild = pChild->NextSibling()) {
		int t = pChild->Type();
		if (t == TiXmlNode::ELEMENT) {
			string element_value(pChild->Value());
			if (element_value == "surface")
				objects.push_back(surfaceAttrib(pChild->ToElement()));
			else if (element_value == "cell")
				objects.push_back(cellAttrib(pChild->ToElement()));
			else if (element_value == "lattice")
				objects.push_back(latticeAttrib(pChild->ToElement()));
			else {
				vector<string> keywords;
				keywords.push_back(element_value);
				throw KeywordParserError("Unrecognized geometry keyword <" + element_value + ">",keywords);
			}
		}
	}

}
Пример #13
0
void XCFParser::parsePartitioning(TiXmlElement* root){
    TiXmlNode* node = root->FirstChild();


    while (node != NULL){
        if (node->Type() == TiXmlNode::TINYXML_ELEMENT) {
            TiXmlElement* element = (TiXmlElement*)node;
            TiXmlString name(node->Value());

            if (name == XCFMapping::PARTITIONING) {
                parsePartitioning(element);
            }else if (name == XCFMapping::PARTITION) {
                parsePartition(element);
            }else {
                cerr << "Invalid node "<< name.c_str() << endl;
                exit(1);
            }

        }
        node = node->NextSibling();
    }
}
Пример #14
0
Scene* SceneLoader::loadScene(Ogre::DataStreamPtr &data)
{
    TiXmlDocument* doc = loadDocument(data);
    TiXmlElement* root = doc->RootElement();
    Scene* scene = new Scene(getAttributeValueAsString(root, "name"));
    
    for (TiXmlNode* cur = root->FirstChild(); cur; cur = cur->NextSibling())
    {
        if (cur->Type() == TiXmlNode::ELEMENT)
        {
            TiXmlElement* elem = cur->ToElement();
            if (hasNodeName(elem, "map"))
            {
                scene->addMap(getAttributeValueAsStdString(elem, "file"));
            }
        }
    }

    delete doc;

    return scene;
}
Пример #15
0
bool CButtonTranslator::LoadKeymap(const CStdString &keymapPath)
{
  TiXmlDocument xmlDoc;

  CLog::Log(LOGINFO, "Loading %s", keymapPath.c_str());
  if (!xmlDoc.LoadFile(keymapPath))
  {
    CLog::Log(LOGERROR, "Error loading keymap: %s, Line %d\n%s", keymapPath.c_str(), xmlDoc.ErrorRow(), xmlDoc.ErrorDesc());
    return false;
  }
  TiXmlElement* pRoot = xmlDoc.RootElement();
  CStdString strValue = pRoot->Value();
  if ( strValue != "keymap")
  {
    CLog::Log(LOGERROR, "%s Doesn't contain <keymap>", keymapPath.c_str());
    return false;
  }
  // run through our window groups
  TiXmlNode* pWindow = pRoot->FirstChild();
  while (pWindow)
  {
    if (pWindow->Type() == TiXmlNode::ELEMENT)
    {
      int windowID = WINDOW_INVALID;
      const char *szWindow = pWindow->Value();
      if (szWindow)
      {
        if (strcmpi(szWindow, "global") == 0)
          windowID = -1;
        else
          windowID = TranslateWindow(szWindow);
      }
      MapWindowActions(pWindow, windowID);
    }
    pWindow = pWindow->NextSibling();
  }

  return true;
}
Пример #16
0
void CGUIIncludes::ResolveExpressions(TiXmlElement *node)
{
  if (!node)
    return;

  TiXmlNode *child = node->FirstChild();
  if (child && child->Type() == TiXmlNode::TINYXML_TEXT && m_expressionNodes.count(node->ValueStr()))
  {
    child->SetValue(ResolveExpressions(child->ValueStr()));
  }
  else
  {
    TiXmlAttribute *attribute = node->FirstAttribute();
    while (attribute)
    {
      if (m_expressionAttributes.count(attribute->Name()))
        attribute->SetValue(ResolveExpressions(attribute->ValueStr()));

      attribute = attribute->Next();
    }
  }
}
Пример #17
0
bool WSWorld::init()
{
	m_worldPopulation = 0;
	if( !loadTerrain( WSApp::instance()->getSetting("/config/WorldCfg")) )
		return false;

	TiXmlDocument	doc;
	CLog::instance()->log(CLog::msgFlagResources, CLog::msgLvlInfo,__FUNCTION__, _("Loading mobs info..."));
	doc.LoadFile("../data/zones/teeran/mobs.xml");
	if (doc.Error())
	{
		CLog::instance()->log(CLog::msgFlagResources, CLog::msgLvlError,__FUNCTION__, _("XML parser returned an error: %s\n"), doc.ErrorDesc());
		return false;
	}


	TiXmlElement* mobsxml = doc.FirstChildElement("mobs");
	CWorldCharMob::setDefaults(mobsxml);

	TiXmlNode* childNode;
	for ( childNode = mobsxml->FirstChild(); childNode != 0; childNode = childNode->NextSibling() )
		if (childNode->Type() == TiXmlNode::ELEMENT)
			if (!strcmp(childNode->Value(), "mob"))
//			{
				insertEntity(WSEntityPtr(new CWorldCharMob(getNewEntityID(), childNode->ToElement())));
//			 	CharMobPtr mob(new CWorldCharMob(childNode->ToElement()));
//				insertCharMob(mob);
//			}
			else if (!strcmp(childNode->Value(), "flock"))
//			{
				insertEntity(WSEntityPtr(new CMobFlock(getNewEntityID(), childNode->ToElement())));
//				MobFlockPtr flock(new CMobFlock(childNode->ToElement()));
//				m_flocks.push_back(flock);
//			}

	CLog::instance()->log(CLog::msgFlagResources, CLog::msgLvlInfo,__FUNCTION__, _("WSWorld.init: Done."));
	return true;
};
Пример #18
0
void
XmlPrototypesFile::LoadPrototypes()
{
    TiXmlNode* node = m_File.RootElement();

    if( node == NULL || node->ValueStr() != "prototypes" )
    {
        LOG_ERROR( "UI Manager: " + m_File.ValueStr() + " is not a valid prototypes file! No <prototypes> in root." );
        return;
    }

    node = node->FirstChild();
    while( node != NULL )
    {
        if( node->Type() == TiXmlNode::TINYXML_ELEMENT && node->ValueStr() == "prototype" )
        {
            Ogre::String name = GetString( node, "name" );
            UiManager::getSingleton().AddPrototype( name, node->Clone() );
        }

        node = node->NextSibling();
    }
}
/***********************************************************************************************************
 * 程序作者:赵进军
 * 函数功能:获取 XML文件所有的数据
 * 参数说明:null
 * 注意事项:null
 * 修改日期:2015/12/14 23:10:00
 ***********************************************************************************************************/
void OperationProfile_XML::GetXmlDataAll(TiXmlNode* pRootEle, char* groupName)
{
	if (NULL == pRootEle)
		return;

	TiXmlNode* pElement = pRootEle->FirstChild();
	TiXmlElement* element;
	TiXmlAttribute* attr;
	int kl;
	for (; pElement; pElement = pElement->NextSibling())
	{
		int nType = pElement->Type();
		switch (nType)
		{
		case TiXmlNode::TINYXML_ELEMENT:
			element = pElement->ToElement();
			if (element != NULL)
			{
				attr = element->FirstAttribute();
				if (attr != NULL)
					std::cout << attr->Value() << std::endl;
			}
			GetXmlDataAll(pElement, groupName);
			break;

		case TiXmlNode::TINYXML_TEXT:
			std::cout << pElement->Value() << std::endl;
			break;

		case TiXmlNode::TINYXML_DOCUMENT:
			kl = 0;
			break;
		default:
			break;
		}
	}
}
Пример #20
0
const Ogre::String
XmlMapFile::GetWalkmeshFileName()
{
    TiXmlNode* node = m_File.RootElement();

    if( node == NULL || node->ValueStr() != "map" )
    {
        LOG_ERROR( "Field Map XML Manager: " + m_File.ValueStr() + " is not a valid fields map file! No <map> in root." );
        return "";
    }

    node = node->FirstChild();
    while( node != NULL )
    {
        if( node->Type() == TiXmlNode::TINYXML_ELEMENT && node->ValueStr() == "walkmesh" )
        {
            return GetString( node, "file_name" );
        }
        node = node->NextSibling();
    }

    LOG_WARNING( "Can't find field's walkmesh in " + m_File.ValueStr() + "." );
    return "";
}
void CKSXML_Create_Project::Parse_Project_Info(TiXmlNode* pParent)
{
	if ( !pParent ) return ;

	
	TiXmlAttribute* pAttrib	=	pParent->ToElement()->FirstAttribute();
	tint32 ival;
	
	// set project ID
	if (pAttrib && pAttrib->QueryIntValue(&ival)==TIXML_SUCCESS)  {
		
		gpApplication->SetGlobalParm(giParamID_Project_ID, ival, giSectionGlobal);
		
	}
		
	
	// parse all childs
	TiXmlNode* pChild;
	for ( pChild = pParent->FirstChild(); pChild != 0; pChild = pChild->NextSibling()) 
	{
		if(pChild->Type() == TiXmlNode::ELEMENT)
			Write_Project_Info(pChild);
	}
}
void CKSXML_Read_Project::Read_Master_Out(TiXmlElement* pElement)
{
	if ( !pElement ) return ;
	
	
	TiXmlNode* pChild;
	
	for ( pChild = pElement->FirstChild(); pChild != 0; pChild = pChild->NextSibling()) {
		
		if(pChild->Type() == TiXmlNode::ELEMENT){
			
			if (stricmp("volume", pChild->Value()) == 0) {

				Set_DAW_Parameter(pChild, giTinyXml_Type_Float, 0, 0);

			}
			else if (stricmp("pan", pChild->Value()) == 0) {

				Set_DAW_Parameter(pChild, giTinyXml_Type_Float, 0, 0);

			}
		}
	}
}
void CKSXML_Read_Project::Read_Master_Aux_Return(TiXmlElement* pElement)
{
	if ( !pElement ) return ;
	
	TiXmlAttribute* pAttrib	=	pElement->FirstAttribute();
	tint32 ival;
	
	// aux id
	if (pAttrib->QueryIntValue(&ival)==TIXML_SUCCESS)    
		;//printf( "AUX %d return: ", ival);
	
	TiXmlNode* pChild;
	
	for ( pChild = pElement->FirstChild(); pChild != 0; pChild = pChild->NextSibling()) {
		
		if(pChild->Type() == TiXmlNode::ELEMENT){
			
			if (stricmp("volume", pChild->Value()) == 0) {
				Set_DAW_Parameter(pChild, giTinyXml_Type_Float, 0, 0);

			}
		}
	}
}
void CKSXML_Read_Project::Read_Track_Region_Fade(TiXmlElement* pElement, CRegion_Data* pRegion_Data)
{
	if ( !pElement ) return ;
	
	TiXmlNode* pChild;
	
	for ( pChild = pElement->FirstChild(); pChild != 0; pChild = pChild->NextSibling()) {
		
		if(pChild->Type() == TiXmlNode::ELEMENT){
			
			if (stricmp("in", pChild->Value()) == 0) {
				
				TiXmlNode* pValue = pChild->FirstChild();
				
				if(pValue) {
					std::string sValue = pValue->Value();
					tuint uiValue = atoi(sValue.c_str());
					pRegion_Data->Fade_In_Duration(uiValue);
				}

			}
			else if (stricmp("out", pChild->Value()) == 0) {

				TiXmlNode* pValue = pChild->FirstChild();
				
				if(pValue) {
					std::string sValue = pValue->Value();
					tuint uiValue = atoi(sValue.c_str());
					pRegion_Data->Fade_Out_Duration(uiValue);
				}

			}

		}
	}
}
Пример #25
0
bool CSettings::Open(String strPath, bool bCreate, bool bSave)
{
	// Flag we are not allowed to save the file by default
	m_bSave = false;

	// Load the default settings
	LoadDefaults();

	// Does the settings file not exist?
	bool bExists = true;

	if(!SharedUtility::Exists(strPath.Get()))
	{
		if(!bCreate)
		{
			CLogFile::Printf("ERROR: Settings file %s does not exist.", strPath.Get());
			return false;
		}
		else
		{
			CLogFile::Printf("WARNING: Settings file %s does not exist, it will now be created.", strPath.Get());

			// Attempt to open the file for write
			FILE * fFile = fopen(strPath.Get(), "w");

			// Ensure the file was opened
			if(!fFile)
			{
				CLogFile::Printf("WARNING: Failed to create settings file %s, no settings will be loaded or saved.", strPath.Get());

				// Flag the settings file as does not exist
				bExists = false;
			}
			else
			{
				// Write the default contents to the file
				fprintf(fFile, "<settings />");

				// Close the file
				fclose(fFile);
			}
		}
	}

	// Load the settings file
	if(bExists)
	{
		// Attempt to load the XML file
		if(m_XMLDocument.LoadFile(strPath.Get()))
		{
			// Flag ourselves as open
			m_bOpen = true;

			// Loop through all XML nodes
			for(TiXmlNode * pNode = m_XMLDocument.RootElement()->FirstChildElement(); pNode; pNode = pNode->NextSibling())
			{
				// Is this not an element node?
				if(pNode->Type() != TiXmlNode::ELEMENT)
					continue;

				// Get the setting and value
				String strSetting = pNode->Value();
				String strValue = pNode->ToElement()->GetText();

				// Does the setting not exist?
				if(!Exists(strSetting))
					CLogFile::Printf("WARNING: Log file setting %s does not exist.", strSetting.Get());
				else
					SetEx(strSetting, strValue);
			}

			// Flag if we are allowed to save the file
			m_bSave = bSave;

			// Save the XML file
			Save();
		}
		else
		{
			if(bCreate)
			{
				CLogFile::Printf("ERROR: Failed to open settings file %s.", strPath.Get());
				return false;
			}
			else
				CLogFile::Printf("WARNING: Failed to open settings file %s, no settings will be loaded or saved.", strPath.Get());
		}
	}

	return true;
}
Пример #26
0
bool CSettings::Save()
{
	// Are we not flagged as open?
	if(!m_bOpen)
		return false;

	// Are we not flagged as allowed to save the file?
	if(!m_bSave)
		return false;

	// Loop through all values
	for(std::map<String, SettingsValue *>::iterator iter = m_values.begin(); iter != m_values.end(); iter++)
	{
		// Get the setting pointer
		SettingsValue * setting = iter->second;

		// Find all nodes for this value
		bool bFoundNode = false;

		for(TiXmlNode * pNode = m_XMLDocument.RootElement()->FirstChildElement(iter->first.Get()); pNode; pNode = pNode->NextSibling())
		{
			// Is this not an element node?
			if(pNode->Type() != TiXmlNode::ELEMENT)
				continue;

			// Is this not the node we are looking for?
			if(iter->first.Compare(pNode->Value()))
				continue;

			// Is this a list node?
			if(setting->IsList())
			{
				// Remove the node
				m_XMLDocument.RootElement()->RemoveChild(pNode);
			}
			else
			{
				// Clear the node
				pNode->Clear();

				// Get the node value
				String strValue = GetEx(iter->first);

				// Create a new node value
				TiXmlText * pNewNodeValue = new TiXmlText(strValue.Get());

				// Add the new node value to the new node
				pNode->LinkEndChild(pNewNodeValue);
			}

			// Flag as found a node
			bFoundNode = true;
			break;
		}

		// Is this a list value?
		if(setting->IsList())
		{
			// Loop through each list item
			for(std::list<String>::iterator iter2 = setting->listValue.begin(); iter2 != setting->listValue.end(); iter2++)
			{
				// Create a new node
				TiXmlElement * pNewNode = new TiXmlElement(iter->first.Get());

				// Create a new node value
				TiXmlText * pNewNodeValue = new TiXmlText((*iter2).Get());

				// Add the new node value to the new node
				pNewNode->LinkEndChild(pNewNodeValue);

				// Add the new node to the XML document
				m_XMLDocument.RootElement()->LinkEndChild(pNewNode);
			}
		}
		else
		{
			// Do we need to create a new node?
			if(!bFoundNode)
			{
				// Create a new node
				TiXmlElement * pNewNode = new TiXmlElement(iter->first.Get());

				// Get the node value
				String strValue = GetEx(iter->first);

				// Create a new node value
				TiXmlText * pNewNodeValue = new TiXmlText(strValue.Get());

				// Add the new node value to the new node
				pNewNode->LinkEndChild(pNewNodeValue);

				// Add the new node to the XML document
				m_XMLDocument.RootElement()->LinkEndChild(pNewNode);
			}
		}
	}

	// Save the XML document
	return m_XMLDocument.SaveFile();
}
Пример #27
0
string ProRataConfig::getValue( TiXmlDocument &txdDoc, 
		const vector<string> &vsTagList )
{
	// Check to see if the provided XML node is valid.
	// If yes, extract the value from the node return it.
	// If no, return emply string.

	// creat a pointer to a node
	TiXmlNode * txnTemp = NULL;

	// check if the tree path is not empty
	if ( vsTagList.size() < 1 )
		return string("");
	
	// iterator for the input vsTagList
	vector<string>::const_iterator itrTagListItr;
	itrTagListItr = vsTagList.begin();

	// move the pointer to txddoc's first child with the specified tag name
	txnTemp = txdDoc.FirstChild( (*itrTagListItr ).c_str() );

	// check if this element exists
	if ( ! txnTemp )
	{
		cout << "ERROR: TAG\"" << (*itrTagListItr) << 
			"\" not found in the configuration file." << endl;
		return string("");
	}

	itrTagListItr++;

	// move the pointer down the hierarchial tree of elements
	for( ; itrTagListItr != vsTagList.end(); itrTagListItr++ )
	{

		txnTemp = txnTemp->FirstChild( (*itrTagListItr ).c_str() );

		if ( ! txnTemp )
		{
			cout << "ERROR: TAG\"" << (*itrTagListItr) << 
				"\" not found in the configuration file." << endl;
			return string("");
		}

	}

	// move the iterator back to point it to the last element name
	itrTagListItr--;

	/*
	 * inside the pointed element, there could be a mixture of
	 * text nodes, comment nodes and element nodes
	 * loop thru every nodes and for each text nodes, retrieve their text
	 * concatenate the text together and return them
	 */
	
	TiXmlText *txs;
	string sTemp = "";
	
	// point txnTemp to the child nodes and loop thru every child node
	for( txnTemp = txnTemp->FirstChild(); txnTemp; txnTemp = txnTemp->NextSibling() )
	{
		// if this node is pointing to a node of type TEXT, which equals 4 in enum NodeType
		if( txnTemp->Type() == 4 )
		{
			// cast txnTemp to a text node
			txs = txnTemp->ToText();
			// get txnTemp's value and then append it to sTemp
			if( txs )
				sTemp.append( txs->Value() );
		}
	}

	return sTemp;
}
Пример #28
0
bool CPlayListASX::LoadData(istream& stream)
{
  CLog::Log(LOGNOTICE, "Parsing ASX");

  if(stream.peek() == '[')
  {
    return LoadAsxIniInfo(stream);
  }
  else
  {
    CXBMCTinyXML xmlDoc;
    stream >> xmlDoc;

    if (xmlDoc.Error())
    {
      CLog::Log(LOGERROR, "Unable to parse ASX info Error: %s", xmlDoc.ErrorDesc());
      return false;
    }

    TiXmlElement *pRootElement = xmlDoc.RootElement();

    // lowercase every element
    TiXmlNode *pNode = pRootElement;
    TiXmlNode *pChild = NULL;
    CStdString value;
    value = pNode->Value();
    value.ToLower();
    pNode->SetValue(value);
    while(pNode)
    {
      pChild = pNode->IterateChildren(pChild);
      if(pChild)
      {
        if (pChild->Type() == TiXmlNode::TINYXML_ELEMENT)
        {
          value = pChild->Value();
          value.ToLower();
          pChild->SetValue(value);

          TiXmlAttribute* pAttr = pChild->ToElement()->FirstAttribute();
          while(pAttr)
          {
            value = pAttr->Name();
            value.ToLower();
            pAttr->SetName(value);
            pAttr = pAttr->Next();
          }
        }

        pNode = pChild;
        pChild = NULL;
        continue;
      }

      pChild = pNode;
      pNode = pNode->Parent();
    }
    CStdString roottitle = "";
    TiXmlElement *pElement = pRootElement->FirstChildElement();
    while (pElement)
    {
      value = pElement->Value();
      if (value == "title")
      {
        roottitle = pElement->GetText();
      }
      else if (value == "entry")
      {
        CStdString title(roottitle);

        TiXmlElement *pRef = pElement->FirstChildElement("ref");
        TiXmlElement *pTitle = pElement->FirstChildElement("title");

        if(pTitle)
          title = pTitle->GetText();

        while (pRef)
        { // multiple references may apear for one entry
          // duration may exist on this level too
          value = pRef->Attribute("href");
          if (value != "")
          {
            if(title.IsEmpty())
              title = value;

            CLog::Log(LOGINFO, "Adding element %s, %s", title.c_str(), value.c_str());
            CFileItemPtr newItem(new CFileItem(title));
            newItem->SetPath(value);
            Add(newItem);
          }
          pRef = pRef->NextSiblingElement("ref");
        }
      }
      else if (value == "entryref")
      {
        value = pElement->Attribute("href");
        if (value != "")
        { // found an entryref, let's try loading that url
          auto_ptr<CPlayList> playlist(CPlayListFactory::Create(value));
          if (NULL != playlist.get())
            if (playlist->Load(value))
              Add(*playlist);
        }
      }
      pElement = pElement->NextSiblingElement();
    }
  }

  return true;
}
Пример #29
0
OsStatus
ExtensionDB::load()
{
    // Critical Section here
    OsLock lock( sLockMutex );
    OsStatus result = OS_SUCCESS;

    if ( m_pFastDB != NULL ) 
    {
        // Clean out the existing DB rows before loading
        // a new set from persistent storage
        removeAllRows ();

        UtlString fileName = OsPath::separator + mDatabaseName + ".xml";
        UtlString pathName = SipXecsService::Path(SipXecsService::DatabaseDirType,
                                                  fileName.data());

        OsSysLog::add(FAC_DB, PRI_DEBUG, "ExtensionDB::load loading \"%s\"",
                    pathName.data());

        TiXmlDocument doc ( pathName );

        // Verify that we can load the file (i.e it must exist)
        if( doc.LoadFile() )
        {
            // the checksum is used to determine if the db changed between reloads
            int loadChecksum = 0;
            TiXmlNode * rootNode = doc.FirstChild ("items");
            if (rootNode != NULL)
            {
                // the folder node contains at least the name/displayname/
                // and autodelete elements, it may contain others
                for( TiXmlNode *itemNode = rootNode->FirstChild( "item" );
                     itemNode; 
                     itemNode = itemNode->NextSibling( "item" ) )
                {
                    // Create a hash dictionary for element attributes
                    UtlHashMap nvPairs;

                    for( TiXmlNode *elementNode = itemNode->FirstChild();
                         elementNode; 
                         elementNode = elementNode->NextSibling() )
                    {
                        // Bypass comments and other element types only interested
                        // in parsing element attributes
                        if ( elementNode->Type() == TiXmlNode::ELEMENT )
                        {
                            UtlString elementName = elementNode->Value();
                            UtlString elementValue;

                            result = SIPDBManager::getAttributeValue (
                                *itemNode, elementName, elementValue);

                            // update the load checksum
                            loadChecksum += ( elementName.hash() + elementValue.hash() );
                            if (result == OS_SUCCESS)
                            {
                                UtlString* collectableKey = 
                                    new UtlString( elementName ); 
                                UtlString* collectableValue = 
                                    new UtlString( elementValue ); 
                                nvPairs.insertKeyAndValue ( 
                                    collectableKey, collectableValue );
                            } else if ( elementNode->FirstChild() == NULL )
                            {
                                // NULL Element value create a special 
                                // char string we have key and value so insert
                                UtlString* collectableKey = 
                                    new UtlString( elementName ); 
                                UtlString* collectableValue = 
                                    new UtlString( SPECIAL_IMDB_NULL_VALUE ); 
                                nvPairs.insertKeyAndValue ( 
                                    collectableKey, collectableValue );
                            }
                        }
                    }
                    // Insert the item row into the IMDB
                    insertRow ( nvPairs );
                }
            }
        } else 
        {
            OsSysLog::add(FAC_SIP, PRI_WARNING, "ExtensionDB::load failed to load \"%s\"",
                    pathName.data());
            result = OS_FAILED;
        }
    } else
    {
        result = OS_FAILED;
    }
    return result;
}
Пример #30
0
void Gameplay::entityInit(Object * p)
{
    // load config
    _config = new TiXmlDocument( "./cfg/config.xml" );
    _config->LoadFile();

    // read pitch shift option    
    TiXmlElement* xmlSound = Gameplay::iGameplay->getConfigElement( "sound" ); assert( xmlSound );
    int pitchShift;
    xmlSound->Attribute( "pitchShift", &pitchShift );
    _pitchShiftIsEnabled = ( pitchShift != 0 );   

	// read cheats option    
    TiXmlElement* details = Gameplay::iGameplay->getConfigElement( "details" ); assert( details );
    int cheats;
    details->Attribute( "cheats", &cheats );
    _cheatsEnabled = ( cheats != 0 );  

	// read free jumping mode  
    int freemode;
    details->Attribute( "freemode", &freemode );
    _freeModeIsEnabled = ( freemode != 0 ); 

	// read meters / feet mode  
    int units;
    details->Attribute( "units", &units );
    _feetModeIsEnabled = ( units != 0 ); 

    // setup random number generation
    getCore()->getRandToolkit()->setSeed( GetTickCount() );


    // retrieve interfaces
    queryInterface( "Engine", &iEngine ); assert( iEngine );
    queryInterface( "Gui", &iGui ); assert( iGui );
    queryInterface( "Language", &iLanguage ); assert( iLanguage );
    queryInterface( "Input", &iInput ); assert( iInput );
    queryInterface( "Audio", &iAudio ); assert( iAudio );
    if( !iAudio || !iInput || !iLanguage || !iGui || !iEngine )
    {
        throw Exception( "One or more core modules are not found, so gameplay will Crash Right Now!" );
    }

    // check language module
    if( wcscmp( iLanguage->getVersionString(), ::version.getVersionString() ) != 0 )
    {
        // incompatible module? - show no localization data
        iLanguage->reset();
    }

	getCore()->logMessage("Version: %ls (Clean)", ::version.getVersionString());

    // create input device
    _inputDevice = iInput->createInputDevice();
    createActionMap();

    // create physics resources
	foundation = PxCreateFoundation(PX_PHYSICS_VERSION, gDefaultAllocatorCallback, gDefaultErrorCallback);
    gPhysicsSDK = PxCreatePhysics(PX_PHYSICS_VERSION, *foundation, PxTolerancesScale() );
	pxCooking = PxCreateCooking(PX_PHYSICS_VERSION, *foundation, PxCookingParams(PxTolerancesScale()));
	PxInitExtensions(*gPhysicsSDK);

	//PHYSX3
    //NxGetPhysicsSDK()->setParameter( NX_VISUALIZATION_SCALE, 100.0f );
    //NxGetPhysicsSDK()->setParameter( NX_VISUALIZE_ACTOR_AXES, 1 );
    //NxGetPhysicsSDK()->setParameter( NX_VISUALIZE_COLLISION_SHAPES, 1 );
    //NxGetPhysicsSDK()->setParameter( NX_VISUALIZE_COLLISION_STATIC, 1 );
    //NxGetPhysicsSDK()->setParameter( NX_VISUALIZE_COLLISION_DYNAMIC,1 );

    // generate user community events from XML documents
    generateUserCommunityEvents();

    // open index
    TiXmlDocument* index = new TiXmlDocument( "./usr/index.xml" );
    index->LoadFile();

    // enumerate career nodes
    TiXmlNode* child = index->FirstChild();
    if( child ) do 
    {
        if( child->Type() == TiXmlNode::ELEMENT && strcmp( child->Value(), "career" ) == 0 )
        {
            _careers.push_back( new Career( static_cast<TiXmlElement*>( child ) ) );
        }
        child = child->NextSibling();
    }
    while( child != NULL );

    // close index document
    delete index;

    // create career for LICENSED_CHAR
    #ifdef GAMEPLAY_EDITION_ATARI
        createLicensedCareer();
    #endif

    // determine afterfx configuration
    TiXmlElement* video = getConfigElement( "video" ); assert( video );
    int afterfx = 0;
    video->Attribute( "afterfx", &afterfx );

    // create render target
    if( afterfx &&
        iEngine->isPfxSupported( engine::pfxBloom ) &&
        iEngine->isPfxSupported( engine::pfxMotionBlur ) )
    {
        _renderTarget = new AfterFxRT();
    }
    else
    {
        _renderTarget = new SimpleRT();
    }

    // play menu music
    playSoundtrack( "./res/sounds/music/dirty_moleculas_execution.ogg" );

    // evaluation protection
    #ifdef GAMEPLAY_EVALUATION_TIME
        SYSTEMTIME evaluationTime = GAMEPLAY_EVALUATION_TIME;
        SYSTEMTIME latestFileTime;
        if( getLatestFileTimeB( &latestFileTime ) )
        {
            if( isGreaterTime( &latestFileTime, &evaluationTime ) )
            {
                pushActivity( new Messagebox( Gameplay::iLanguage->getUnicodeString( 765 ) ) );
            }
            else
            {
                // startup
                _preloaded = new Preloaded();
                pushActivity( _preloaded );
            }
        }
    #else
        // determine if licence is required to play game
        bool licenceIsRequired = false;
        #ifndef GAMEPLAY_EDITION_ND
            #ifndef GAMEPLAY_EDITION_ATARI
                #ifndef GAMEPLAY_EDITION_POLISH
                    licenceIsRequired = false;
                #endif
            #endif
        #endif

        // startup        
        _preloaded = new Preloaded();
        pushActivity( _preloaded );
    #endif   
}