tinyxml初体验

 

  在tinyxml主页http://www.grinninglizard.com/tinyxml/下载源码,解压,用VC开发工具打开,得到tinyxmld.lib静态库。

 

提取出tinyxml.h tinystr.h tinyxml.lib,添加到同一个文件夹中,例如命名为tinyxml文件夹,然后把这个路径添加进去VC开发工具的路径中。

编写测试代码,测试代码是抄的,再此:http://panpan.blog.51cto.com/489034/104961 我改动了一些

xml测试代码:

 

    
        
            88208888
            

西安市太白南路二号 88206666 西安市光华路 213123123 wuhan

解析代码:

//
// tinyxml library test
//

#include 
#include 
#include "tinyxml.h"
using std::string;

#pragma comment(lib, "tinyxmld.lib")

int main()
{
	TiXmlDocument* myDocument = new TiXmlDocument();
	myDocument->LoadFile("d:\\test.xml");
	TiXmlElement* rootElement = myDocument->RootElement();
	TiXmlElement* studentsElement = rootElement->FirstChildElement();

	
	TiXmlElement* studentElement = studentsElement->FirstChildElement();
	while (studentElement) {
		TiXmlAttribute* attributeOfStudent= studentElement->FirstAttribute();
		while (attributeOfStudent) {
			std::cout<Name()<<" : "<Value()<Next();
		}
		TiXmlElement* phoneElement = studentElement->FirstChildElement();
		std::cout<<"Phone "<<" : "<GetText()<NextSiblingElement();
		std::cout<<"address "<<" : "<GetText()<NextSiblingElement();
	}

	return 0;
}

 

 

 

 

至此体验完毕,比较简单,以后要研究一下XML解析,主要是想写一个界面和逻辑分离的程序,现在正在研究DirectUI,

一般都是用脚本语言配置界面 :)。

 

编辑有问题,xml源码可在我参照的网站上找到,我贴了几次代码,都不能把XML代码和C++代码贴一起,难道这个博客编辑器

限制行数?


你可能感兴趣的:(tinyxml初体验)