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


C++ TiXmlDeclaration::Standalone方法代码示例

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


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

示例1: readSchoolXml

void readSchoolXml() 
{
	using namespace std;

	const char *xmlFile = "conf/school.xml";

	TiXmlDocument doc;
	if (!doc.LoadFile(xmlFile))
	{
		cout << "Load xml file failed.\t" << xmlFile << endl;
		return;
	}

	cout << "Load xml file OK." << endl;
	
	TiXmlDeclaration *decl = doc.FirstChild()->ToDeclaration();

	if (!decl)
	{
		cout << "decl is null.\n" << endl;
		return;
	}
	
	cout <<  decl->Encoding();
	cout <<  decl->Version();
	cout <<  decl->Standalone() << endl;



	TiXmlHandle docHandle(&doc);
	TiXmlElement *child 
		= docHandle.FirstChild("School").FirstChild("Class").Child("Student", 0).ToElement();

	for ( ; child != NULL; child = child->NextSiblingElement())
	{
		TiXmlAttribute *attr = child->FirstAttribute();

		for (; attr != NULL; attr = attr->Next())
		{
			cout << attr->Name() << " : " << attr->Value() << endl;
		}
		
		TiXmlElement *ct = child->FirstChildElement();
		for (; ct != NULL; ct = ct->NextSiblingElement())
		{
			char buf[1024] = {0};
			u2g(ct->GetText(), strlen(ct->GetText()), buf, sizeof(buf));
			cout << ct->Value() << " : " << buf << endl;
		}
		cout << "=====================================" << endl;
	}
	
	TiXmlElement *schl = doc.RootElement();
	const char *value_t =schl->Attribute("name");
	
	char buf[1024] = {0};
	if ( u2g(value_t, strlen(value_t), buf, sizeof(buf)) == -1) {
		return;
	}
	cout << "Root Element value: " << buf << endl;
	schl->RemoveAttribute("name");
	schl->SetValue("NewSchool");


	cout << "Save file: " << (doc.SaveFile("conf/new.xml") ? "Ok" : "Failed") << endl;

return ;
	TiXmlElement *rootElement = doc.RootElement();
	TiXmlElement *classElement = rootElement->FirstChildElement();
	TiXmlElement *studentElement = classElement->FirstChildElement();


	// N 个 Student 节点
	for ( ; studentElement!= NULL; studentElement = studentElement->NextSiblingElement()) 
	{
		// 获得student
		TiXmlAttribute *stuAttribute = studentElement->FirstAttribute();
		for (; stuAttribute != NULL; stuAttribute = stuAttribute->Next()) 
		{
			cout << stuAttribute->Name() << " : " << stuAttribute->Value() << endl;
		}

		// 获得student的第一个联系方式 
		TiXmlElement *contact = studentElement->FirstChildElement();
		for (; contact != NULL; contact = contact->NextSiblingElement())
		{
			const char *text = contact->GetText();
			char buf[1024] = {0};
			if ( u2g(text, strlen(text), buf, sizeof(buf)) == -1) {
				continue;
			}
			cout << contact->Value() << " : " << buf << endl; 
		}
	}
}
开发者ID:PoppyRobot,项目名称:codeStudy,代码行数:95,代码来源:main.cpp


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