Ejemplo n.º 1
0
int main()  
{      
	XmlDocument doc("config.xml");
	// 获取connect节点 
	XmlNode connect = doc.firstNode("connect");  

	// 获取全局属性配置
	XmlNode node = connect.firstNode("property");
	printf("global property:\n");
	for (; !node.isNull(); node = node.nextSibling("property"))
	{
		printf("name: %s value: %s\n", node["name"], node["value"]);
	}

	XmlNode pool = connect.firstNode("pool");
	printf("pools:\n");
	for (; !pool.isNull(); pool = pool.nextSibling("pool"))
	{
		printf("pool:\n");
		printf("name: %s\n", pool["name"]);
		node = pool.firstNode("property");
		for (; !node.isNull(); node = node.nextSibling("property"))
		{
			printf("name: %s value: %s\n", node["name"], node["value"]);
		}
	}

	doc.save("config.xml2");

	return EXIT_SUCCESS;  
}  
Ejemplo n.º 2
0
int main()
{
	XmlDocument doc;

	doc.parse("<?xml version='1.0' encoding='utf-8' ?><command><user>abc</user><pwd>密码</pwd></command>");
	//doc.parse("<command><user>abc</user><pwd>123</pwd></command>");

	//char a[] = "<command><user>abc</user><pwd>123</pwd></command>";
	//doc.parse(a);
	XmlNode command = doc.firstNode("command");
	XmlNode user = command.firstNode("user");
	XmlNode pwd = command.firstNode("pwd");

	KY_LOG_INFO("user: %s pwd: %s", user.text(), pwd.text());
	doc.save("test.xml");
	
	return 0;
}