当前位置: 首页>>代码示例>>C++>>正文


C++ TiXmlDocument::Print方法代码示例

本文整理汇总了C++中TiXmlDocument::Print方法的典型用法代码示例。如果您正苦于以下问题:C++ TiXmlDocument::Print方法的具体用法?C++ TiXmlDocument::Print怎么用?C++ TiXmlDocument::Print使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在TiXmlDocument的用法示例。


在下文中一共展示了TiXmlDocument::Print方法的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: readSchoolXml

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

        TiXmlElement* studentContactElement = studentElement->FirstChildElement();//获得student的第一个联系方式 
        for (; studentContactElement != NULL; studentContactElement = studentContactElement->NextSiblingElement() ) {
            //string contactType = studentContactElement->Value();
            //string contactValue = studentContactElement->GetText();
            //cout << contactType  << " : " << contactValue << std::endl;           
        }   
     
    } 
}
开发者ID:lidongqiang,项目名称:wvpctool,代码行数:28,代码来源:xmlib.cpp

示例2: printSchoolXml

void printSchoolXml() {
	using namespace std;
	TiXmlDocument doc;  
	const char * xmlFile = "conf/school.xml";	
	if (doc.LoadFile(xmlFile)) {  	
		doc.Print();  
	} else {
		cout << "can not parse xml conf/school.xml" << endl;
	}
}
开发者ID:PoppyRobot,项目名称:codeStudy,代码行数:10,代码来源:main.cpp

示例3: saveXmlToFile

bool TreeImportExport::saveXmlToFile(const TiXmlDocument& doc, const WCHAR * xmlFilePath)
{
	FILE * pFile = 0;
	if (_wfopen_s(&pFile, xmlFilePath, L"wb") == 0)
	{
		doc.Print(pFile);
		fclose(pFile);
		return true;
	}
	else
	{
		return false;
	}
}
开发者ID:KidoPlay,项目名称:Scylla,代码行数:14,代码来源:TreeImportExport.cpp

示例4: libxml_file_load

/**
 * 实现xml文件装载
 * @param[in] xml_file_path xml文件路径
 * @return NULL 装载失败
 * @return !NULL xml dom根节点
 */
libxml_node_t* libxml_file_load(const char* xml_file_path)
{
	TiXmlDocument* doc = new TiXmlDocument(xml_file_path);
	bool loadOkay = doc->LoadFile();

	if (!loadOkay)
	{
		printf("Could not load file '%s'. Error='%s'\n", xml_file_path,
				doc->ErrorDesc());
		return NULL;
	}

	doc->Print(stdout);
	return (libxml_node_t*) doc->RootElement();
}
开发者ID:anlaneg,项目名称:test,代码行数:21,代码来源:tinyxml_adapter.cpp

示例5: ReadXmlEnemyData

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

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

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

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

		vData.push_back(ed);
		keyElement = keyElement->NextSiblingElement();
	}
}
开发者ID:sieg-lu,项目名称:dimensional-sinbad,代码行数:41,代码来源:EnemyManager.cpp

示例6: readXml

void readXml()
{
    TiXmlDocument* myDocument = new TiXmlDocument();
    myDocument->LoadFile("student.xml");
    myDocument->Print();
    TiXmlElement* rootElement = myDocument->RootElement();  //Class    
    TiXmlElement* studentsElement = rootElement->FirstChildElement();  //Students
    TiXmlElement* studentElement = studentsElement->FirstChildElement();  //Students
    //std::cout<<studentElement->GetText() ;    
    while ( studentElement ) 
    {
        TiXmlAttribute* attributeOfStudent = studentElement->FirstAttribute();  //获得student的name属性
        while ( attributeOfStudent ) 
        {
            std::cout << attributeOfStudent->Name() << " : " << attributeOfStudent->Value() << std::endl;
            attributeOfStudent = attributeOfStudent->Next();
        }
        TiXmlElement* phoneElement = studentElement->FirstChildElement();//获得student的phone元素
        std::cout << "phone" << " : " << phoneElement->GetText() << std::endl;
        TiXmlElement* addressElement = phoneElement->NextSiblingElement();
        std::cout << "address" << " : " << phoneElement->GetText() << std::endl;
        studentElement = studentElement->NextSiblingElement();
    }
}
开发者ID:pfeng90,项目名称:Myc2xml,代码行数:24,代码来源:main.cpp

示例7: serialise

void SceneImporter::serialise()
{
	BinaryDataStore<char> binaryDataStore;
	TiXmlDocument doc;
	TiXmlDeclaration* decl = new TiXmlDeclaration("1.0", "", "");
	doc.LinkEndChild(decl);
	TiXmlElement* root = new TiXmlElement("root");
	doc.LinkEndChild(root);
	TiXmlElement* header = new TiXmlElement("Header");
	header->SetAttribute("type", "SkinnedCharacter");
	root->LinkEndChild(header);
	TiXmlElement* prefab = new TiXmlElement("Model");
	root->LinkEndChild(prefab);
	TiXmlElement* meshes = new TiXmlElement("Meshes");
	prefab->LinkEndChild(meshes);
	meshes->SetAttribute("count", _meshes.size());
	for (auto It = _meshes.begin(); It != _meshes.end(); It++)
	{
		auto_ptr<Mesh>& meshPtr = *(It);
		meshPtr->serialise(meshes, binaryDataStore);
	}
	Animator::get()->serialise(prefab, binaryDataStore);
	const char* fileName = "prefab.xml";
	ofstream os;
	binaryDataStore.compact();
	os.open(fileName, ios::binary);
	long numBinaryBytes = binaryDataStore.size();
	os.write((const char*)&numBinaryBytes, sizeof(long));
	const vector<char>& buffer = binaryDataStore.getBuffer();
	os.write(&buffer[0], numBinaryBytes);
	os.close();
	FILE* fp;
	fp = fopen(fileName, "a");
	doc.Print(fp);
	fclose(fp);
}
开发者ID:fawnha,项目名称:morftech,代码行数:36,代码来源:SceneImporter.cpp

示例8: main

int main()
{

	//
	// We start with the 'demoStart' todo list. Process it. And
	// should hopefully end up with the todo list as illustrated.
	//
	const char* demoStart =
		"<?xml version=\"1.0\"  standalone='no' >\n"
		"<!-- Our to do list data -->"
		"<ToDo>\n"
		"<!-- Do I need a secure PDA? -->\n"
		"<Item priority=\"1\" distance='close'> Go to the <bold>Toy store!</bold></Item>"
		"<Item priority=\"2\" distance='none'> Do bills   </Item>"
		"<Item priority=\"2\" distance='far &amp; back'> Look for Evil Dinosaurs! </Item>"
		"</ToDo>";
		
	{

	#ifdef TIXML_USE_STL
		//	What the todo list should look like after processing.
		// In stream (no formatting) representation.
		const char* demoEnd =
			"<?xml version=\"1.0\" standalone=\"no\" ?>"
			"<!-- Our to do list data -->"
			"<ToDo>"
			"<!-- Do I need a secure PDA? -->"
			"<Item priority=\"2\" distance=\"close\">Go to the"
			"<bold>Toy store!"
			"</bold>"
			"</Item>"
			"<Item priority=\"1\" distance=\"far\">Talk to:"
			"<Meeting where=\"School\">"
			"<Attendee name=\"Marple\" position=\"teacher\" />"
			"<Attendee name=\"Voel\" position=\"counselor\" />"
			"</Meeting>"
			"<Meeting where=\"Lunch\" />"
			"</Item>"
			"<Item priority=\"2\" distance=\"here\">Do bills"
			"</Item>"
			"</ToDo>";
	#endif

		// The example parses from the character string (above):
		#if defined( WIN32 ) && defined( TUNE )
		_CrtMemCheckpoint( &startMemState );
		#endif	

		{
			// Write to a file and read it back, to check file I/O.

			TiXmlDocument doc( "demotest.xml" );
			doc.Parse( demoStart );

			if ( doc.Error() )
			{
				printf( "Error in %s: %s\n", doc.Value(), doc.ErrorDesc() );
				exit( 1 );
			}
			doc.SaveFile();
		}

		TiXmlDocument doc( "demotest.xml" );
		bool loadOkay = doc.LoadFile();

		if ( !loadOkay )
		{
			printf( "Could not load test file 'demotest.xml'. Error='%s'. Exiting.\n", doc.ErrorDesc() );
			exit( 1 );
		}

		printf( "** Demo doc read from disk: ** \n\n" );
		printf( "** Printing via doc.Print **\n" );
		doc.Print( stdout );

		{
			printf( "** Printing via TiXmlPrinter **\n" );
			TiXmlPrinter printer;
			doc.Accept( &printer );
			fprintf( stdout, "%s", printer.CStr() );
		}
		#ifdef TIXML_USE_STL	
		{
			printf( "** Printing via operator<< **\n" );
			std::cout << doc;
		}
		#endif
		TiXmlNode* node = 0;
		TiXmlElement* todoElement = 0;
		TiXmlElement* itemElement = 0;


		// --------------------------------------------------------
		// An example of changing existing attributes, and removing
		// an element from the document.
		// --------------------------------------------------------

		// Get the "ToDo" element.
		// It is a child of the document, and can be selected by name.
		node = doc.FirstChild( "ToDo" );
//.........这里部分代码省略.........
开发者ID:huntriver,项目名称:TankVSBugs-CSE380-,代码行数:101,代码来源:xmltest.cpp

示例9: outputMenuList

//case 7:open and write the current menu to a file in RBML  
	void MenuList::outputMenuList(string outFileName){
		
		cout << "Please enter the file name to be saved: " << endl;

		cin >> outFileName;

		TiXmlDocument doc;
		TiXmlDeclaration *declaration = new TiXmlDeclaration ("1.0","UTF-8","");
		doc.LinkEndChild(declaration);

		TiXmlComment *comment = new TiXmlComment ("hi, this is a recipe book");
		doc.LinkEndChild(comment);

		TiXmlElement * menuListElement = new TiXmlElement("menulist");
		doc.LinkEndChild(menuListElement);

		for (int i =0; i < menuList.size(); i++){
		
			TiXmlElement * recipeElement = new TiXmlElement("recipe");
			menuListElement->LinkEndChild(recipeElement);

			TiXmlElement * titleElement = new TiXmlElement("title");
			recipeElement->LinkEndChild(titleElement);

			TiXmlText * titleContent = new TiXmlText("Blackeyed Peas");
			titleElement->LinkEndChild(titleContent);	

		
			TiXmlElement * ingredientslistElement = new TiXmlElement("ingreidentslist");
			recipeElement->LinkEndChild(ingredientslistElement);


			for (int j =0; j < menuList[i].ingredientsList.size();j++){

				TiXmlElement * ingredientElement = new TiXmlElement("ingredient");
				ingredientslistElement->LinkEndChild(ingredientElement);
	
				TiXmlElement * quantityElement = new TiXmlElement("quantity");
				ingredientElement->LinkEndChild(quantityElement);

				TiXmlElement * unitElement = new TiXmlElement("unit");
				ingredientElement->LinkEndChild(unitElement);	

				TiXmlElement * fooditemElement = new TiXmlElement("fooditem");
				ingredientElement->LinkEndChild(fooditemElement);

				//content
				TiXmlText * quantityContent = new TiXmlText("menuList[i].ingredientsList[j].quantity.c_str");
				quantityElement->LinkEndChild(quantityContent);	

				TiXmlText * unitContent = new TiXmlText(menuList[i].ingredientsList[j].unit.c_str());
				unitElement->LinkEndChild(unitContent);	

				TiXmlText * fooditemContent = new TiXmlText(menuList[i].ingredientsList[j].fooditem.c_str());
				fooditemElement->LinkEndChild(fooditemContent);

			}


			TiXmlElement * preparationElement = new TiXmlElement("preparation");
			recipeElement->LinkEndChild(preparationElement);

			for (int j =0; j< menuList[i].equipmentList.size();j++){
				TiXmlElement * equipmentElement = new TiXmlElement("equipment");
				preparationElement->LinkEndChild(equipmentElement);

				TiXmlText* equipmentContent = new TiXmlText(menuList[i].equipmentList[j].equipment.c_str());
				equipmentElement->LinkEndChild(equipmentContent);
			}


		}

		doc.Print();
		doc.SaveFile(outFileName.c_str());

		if (!silent){
			cout << "Save to " << outFileName << " completed" << endl;
		}

		return;
	
	} 
开发者ID:tianwenlan,项目名称:COP3503-Programming-fundamentals-2,代码行数:84,代码来源:COP3503su14_Proj3_WenlanT+copy+2.cpp

示例10: main

int main(int argc, char** argv)
{
    if( argc <  2 ) return -1;
    TiXmlDocument* doc = loadFromFile(argv[1]);

    sofa::core::init();
    int retValue = 0;

    if(doc )
    {
        DiscoverNodes v_nodes;
        DiscoverDisplayFlagsVisitor v_displayFlags;
        doc->Accept(&v_nodes);
        doc->Accept(&v_displayFlags);

        for(unsigned int i=0; i < v_nodes.leaves.size(); ++i )
        {
            createVisualStyleVisitor(v_nodes.leaves[i],v_displayFlags.map_displayFlags);
        }

        for( unsigned int i=0; i < v_nodes.nodes.size(); ++i)
        {
            removeShowAttributes(v_nodes.nodes[i]);
        }

        if( v_nodes.rootNode() )
        {
            std::map<const TiXmlElement*,sofa::core::visual::DisplayFlags*>::iterator it_root;
            it_root = v_displayFlags.map_displayFlags.find(v_nodes.rootNode());
            if( it_root != v_displayFlags.map_displayFlags.end() )
            {
                DisplayFlags* root_flags = it_root->second;
                convert_false_to_neutral(*root_flags);
                TiXmlElement* visualStyle;
                if( ! root_flags->isNeutral() )
                {
                    if( (visualStyle = v_nodes.rootNode()->FirstChildElement("VisualStyle") ) == NULL )
                    {
                        TiXmlElement* visualstyle = new TiXmlElement("VisualStyle");
                        std::ostringstream oss;
                        oss << *root_flags;
                        visualstyle->SetAttribute("displayFlags",oss.str());
                        TiXmlElement* first_child = v_nodes.rootNode()->FirstChildElement();
                        if(first_child) v_nodes.rootNode()->InsertBeforeChild(first_child,*visualstyle);
                        else v_nodes.rootNode()->LinkEndChild(visualstyle);
                    }
                    else
                    {
                        std::ostringstream oss;
                        oss << *root_flags;
                        visualStyle->SetAttribute("displayFlags",oss.str());
                    }
                }
                else
                {
                    if( (visualStyle = v_nodes.rootNode()->FirstChildElement("VisualStyle")) != NULL )
                    {
                        v_nodes.rootNode()->RemoveChild(visualStyle);
                    }
                }
            }
        }

        doc->Print();
        std::cout.flush();
        delete doc;
    }
    else
    {
        return -1;
    }

    sofa::core::cleanup();
    return retValue;
}
开发者ID:FabienPean,项目名称:sofa,代码行数:75,代码来源:main.cpp

示例11: main


//.........这里部分代码省略.........
  kukaConnection = ulapi_socket_get_client_id(KUKA_PORT, "localhost");
  if( kukaConnection < 0 )
    return -1;

  myPose.x = 0.1;
  myPose.y = 0.2;
  myPose.z = 0.3;
  myPose.xrot = 0.4;
  myPose.yrot = 0.5;
  myPose.zrot = 0.6;

  while(true)
    {
      TiXmlDocument kukaCorrections;
      TiXmlHandle correctionsHandle(&kukaCorrections);
      std::string str;
      enum {INBUF_LEN = 2048};
      char inbuf[INBUF_LEN];
      std::ostringstream s;
      cartesianStatus =
	toSendHandle.FirstChild("Rob").FirstChild("Dat").Child(1).ToElement();
      IPOCUpdate = toSendHandle.FirstChild("Rob").FirstChild("Dat").Child(9).
	ToElement();
      jointStatus =
	toSendHandle.FirstChild("Rob").FirstChild("Dat").Child(3).ToElement();
      cartesianStatus->SetDoubleAttribute("X", myPose.x); 
      cartesianStatus->SetDoubleAttribute ("Y", myPose.y);
      cartesianStatus->SetDoubleAttribute ("Z", myPose.z);
      cartesianStatus->SetDoubleAttribute ("A", myPose.xrot);
      cartesianStatus->SetDoubleAttribute ("B", myPose.yrot);
      cartesianStatus->SetDoubleAttribute ("C", myPose.zrot);
      jointStatus->SetDoubleAttribute("A1", myJoints[0]);
      jointStatus->SetDoubleAttribute("A2", myJoints[1]);
      jointStatus->SetDoubleAttribute("A3", myJoints[2]);
      jointStatus->SetDoubleAttribute("A4", myJoints[3]);
      jointStatus->SetDoubleAttribute("A5", myJoints[4]);
      jointStatus->SetDoubleAttribute("A6", myJoints[5]);

      s << counter++;
      s << '\0';
      TiXmlText *text = new TiXmlText((s.str()).c_str());
      IPOCUpdate->Clear();
      IPOCUpdate->LinkEndChild(text);
      //      kukaStatus.Print();
      str << kukaStatus;
      ulapi_socket_write(kukaConnection, str.c_str(), str.length());
      inbuf[0] = '\0';
      nchars = ulapi_socket_read(kukaConnection, inbuf, sizeof(inbuf)-1);
      if (nchars <= 0) 
	{
	  printf("kukaRobot::status client disconnected\n");
	  break;
	}
      else
	{
	inbuf[nchars] = '\0';
	}
      kukaCorrections.Parse(inbuf);
      if(debug) kukaCorrections.Print();
      cartesianUpdate =
	correctionsHandle.FirstChild("Sen").FirstChild("Dat").
	Child(1).ToElement();
      jointUpdate =
	correctionsHandle.FirstChild("Sen").FirstChild("Dat").
	Child(2).ToElement();
      cartesianUpdate->QueryDoubleAttribute("X", &(poseIn.x));
      cartesianUpdate->QueryDoubleAttribute("Y", &(poseIn.y));
      cartesianUpdate->QueryDoubleAttribute("Z", &(poseIn.z));
      cartesianUpdate->QueryDoubleAttribute("A", &(poseIn.xrot));
      cartesianUpdate->QueryDoubleAttribute("B", &(poseIn.yrot));
      cartesianUpdate->QueryDoubleAttribute("C", &(poseIn.zrot));
      jointUpdate->QueryDoubleAttribute("A1", &(jointsIn[0]));
      jointUpdate->QueryDoubleAttribute("A2", &(jointsIn[1]));
      jointUpdate->QueryDoubleAttribute("A3", &(jointsIn[2]));
      jointUpdate->QueryDoubleAttribute("A4", &(jointsIn[3]));
      jointUpdate->QueryDoubleAttribute("A5", &(jointsIn[4]));
      jointUpdate->QueryDoubleAttribute("A6", &(jointsIn[5]));
      myPose.x += poseIn.x;
      myPose.y += poseIn.y;
      myPose.z += poseIn.z;
      myPose.xrot += poseIn.xrot;
      myPose.yrot += poseIn.yrot;
      myPose.zrot += poseIn.zrot;
      for( int i=0; i<ROBOT_DOF; i++ )
	{
	  myJoints[i] += jointsIn[i] * cmdMotorScale[i] / jointMotorScale[i];
	  if( debug )
	    printf( "J%d <%lf %lf> ", i+1, myJoints[i], jointsIn[i] );
	}
      if(debug)
      printf( "\nkukaRobot Status: <%4.2f, %4.2f, %4.2f> <%4.2f, %4.2f, %4.2f>\n\n",
	      myPose.x,
	      myPose.y,
	      myPose.z,
	      myPose.xrot,
	      myPose.yrot,
	      myPose.zrot);
      cycleBlock->wait();
    }
}
开发者ID:usnistgov,项目名称:el-robotics-core,代码行数:101,代码来源:kukaRobot.cpp

示例12: Save


//.........这里部分代码省略.........
            string t=boost::lexical_cast<string>((int)this->LastStarted);
            laststarted->InsertEndChild(TiXmlText(t));
        }
    }

    {
        TiXmlElement *messages=InsertChild(root, "Messages");

        InsertChild(messages, "FirstBlock", this->FirstBlock);
        InsertChild(messages, "FirstHide", this->FirstHide);
    }

    {
        TiXmlElement *portset = InsertChild(root, "PortSet");

        InsertChild(portset, "AllowHttp", this->PortSet.AllowHttp);
        InsertChild(portset, "AllowFtp", this->PortSet.AllowFtp);
        InsertChild(portset, "AllowSmtp", this->PortSet.AllowSmtp);
        InsertChild(portset, "AllowPop3", this->PortSet.AllowPop3);

        TiXmlElement *profiles = InsertChild(portset, "Profiles");
        for (vector<PortProfile>::const_iterator pfit = this->PortSet.Profiles.begin(); pfit != this->PortSet.Profiles.end(); ++pfit) {
            TiXmlElement *profile = InsertChild(profiles, "Profile");

            PortProfile pf = (PortProfile) *pfit;

            InsertChild(profile, "Name", pf.Name);
            InsertChild(profile, "Enabled", pf.Enabled);
            InsertChild(profile, "Type", pf.Type);

            TiXmlElement *ports = InsertChild(profile, "Ports");
            for (vector<PortRange>::const_iterator pit = pf.Ports.begin(); pit != pf.Ports.end(); ++pit) {
                TiXmlElement *range = InsertChild(ports, "Range");
                InsertAttribute(range, (PortRange) *pit);
            }
        }
    }

    {
        TiXmlElement *lists=InsertChild(root, "Lists");

        for(vector<StaticList>::size_type i=0; i<this->StaticLists.size(); i++) {
            TiXmlElement *list=InsertChild(lists, "List");

            InsertChild(list, "File", TSTRING_UTF8(this->StaticLists[i].File.file_str()));
            InsertChild(list, "Type", (this->StaticLists[i].Type==List::Allow)?"allow":"block");
            InsertChild(list, "Description", this->StaticLists[i].Description);
            InsertChild(list, "Enabled", this->StaticLists[i].Enabled);
        }

        for(vector<DynamicList>::size_type i=0; i<this->DynamicLists.size(); i++) {
            TiXmlElement *list=InsertChild(lists, "List");

            InsertChild(list, "Url", this->DynamicLists[i].Url);
            InsertChild(list, "Type", (this->DynamicLists[i].Type==List::Allow)?"allow":"block");
            InsertChild(list, "Description", this->DynamicLists[i].Description);
            InsertChild(list, "Enabled", this->DynamicLists[i].Enabled);
            InsertChild(list, "FailedUpdate", this->DynamicLists[i].FailedUpdate);

            TiXmlElement *lastupdate=InsertChild(list, "LastUpdate");
            if(this->DynamicLists[i].LastUpdate) {
                string s=boost::lexical_cast<string>((int)this->DynamicLists[i].LastUpdate);
                lastupdate->InsertEndChild(TiXmlText(s));
            }

            TiXmlElement *lastdownload=InsertChild(list, "LastDownload");
            if(this->DynamicLists[i].LastDownload) {
                string s=boost::lexical_cast<string>((int)this->DynamicLists[i].LastDownload);
                lastdownload->InsertEndChild(TiXmlText(s));
            }
        }
    }

    {
        TiXmlElement *ibl=InsertChild(root, "I-Blocklist");

        InsertChild(ibl, "Username", this->IblUsername);
        InsertChild(ibl, "PIN", this->IblPin);
    }

    // First save to a temp-file
    std::wstring tempfile = _filename;
    tempfile += L".tmp";
    FILE *fp=_tfopen((path::base_dir()/tempfile.c_str()).file_str().c_str(), _T("w"));
    if(!fp)
    {
        TRACEERR("[Configuration] [Save]", L"Can't open file", GetLastError());
        throw runtime_error("unable to save configuration");
    }
    {
        boost::shared_ptr<void> ptr(fp, fclose);
        doc.Print(fp);
    }

    // Now, only after that's done should we overwrite the original
    path::move((path::base_dir()/tempfile.c_str()), (path::base_dir()/_filename), true);

    TRACEI("[Configuration] [Save]  < Leaving routine.");

} // End of Save()
开发者ID:hskang113,项目名称:peerblock,代码行数:101,代码来源:configuration.cpp


注:本文中的TiXmlDocument::Print方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。