minixml2.9在vs2012与vs2010下的简单使用

首先下载minixml源码

http://www.msweet.org/

minixml中文文档

http://blog.csdn.net/bluesonic/article/details/3887143

使用vs2012或者vs2010打开vcnet文件夹下的mxml.sln

minixml2.9在vs2012与vs2010下的简单使用_第1张图片

若版本较高,则进行升级

minixml2.9在vs2012与vs2010下的简单使用_第2张图片

根据需要的配置(debug or release),生成对应的解决方案

minixml2.9在vs2012与vs2010下的简单使用_第3张图片

拷贝生成的mxml1.dll,mxml1.lib以及原有的mxml.h

minixml2.9在vs2012与vs2010下的简单使用_第4张图片minixml2.9在vs2012与vs2010下的简单使用_第5张图片

新建项目,将刚刚拷贝的文件添加到项目中

minixml2.9在vs2012与vs2010下的简单使用_第6张图片

测试代码

#include "mxml.h"
#include
#include
#include

int main()
{
    FILE *fp;
    mxml_node_t *tree,*node;
	
	printf("Label1.prt\n");
	fp = fopen("Label1.prt","r");
	tree = mxmlLoadFile(NULL,fp,MXML_TEXT_CALLBACK);
	fclose(fp);
	printf("Loop traversal :\n");
	for(node = mxmlFindElement(tree,tree,NULL,NULL,NULL,MXML_DESCEND);
		node != NULL; node = mxmlFindElement(node,tree,NULL,NULL,NULL,MXML_DESCEND)){
			printf("Element name:%s\n",node->value);
			if(strcmp(node->value.opaque,"AreaSize") == 0){
				printf("	Height:%s,Width=%s\n",mxmlElementGetAttr(node,"Height"),mxmlElementGetAttr(node,"Width"));
			}else if(strcmp(node->value.opaque,"ObjectList")==0){
				printf("	count:%s\n",mxmlElementGetAttr(node,"Count"));
			}else if(strcmp(node->value.opaque,"zOrder")==0){
				printf("	zOrder:%d\n",node->child->value.integer);
			}else if(strcmp(node->value.opaque,"Type")==0){
				printf("	Type:%s\n",node->child->value.text.string);
			}else if(strcmp(node->value.opaque,"Start")==0){
				printf("	X=%s,Y=%s,order=%s\n",mxmlElementGetAttr(node,"X"),mxmlElementGetAttr(node,"Y"),mxmlElementGetAttr(node,"order"));
			}else if(strcmp(node->value.opaque,"End")==0){
				printf("	X=%s,Y=%s,order=%s\n",mxmlElementGetAttr(node,"X"),mxmlElementGetAttr(node,"Y"),mxmlElementGetAttr(node,"order"));
			}else if(strcmp(node->value.opaque,"Color")==0){
				printf("	Color:%s\n",node->child->value.text.string);
			}else if(strcmp(node->value.opaque,"PenWidth")==0){
				printf("	PenWidth:%s\n",node->child->value.text.string);
			}else if(strcmp(node->value.opaque,"FillColor")==0){
				printf("	FillColor:%s\n",node->child->value.text.string);
			}else if(strcmp(node->value.opaque,"Name")==0){
				printf("	Name:%s\n",node->child->value.text.string);
			}
	}

	printf("\nSearch traversal :\n");
	node = mxmlFindElement(tree,tree,"AreaSize",NULL,NULL,MXML_DESCEND);
	printf("AreaSize:\n	Height=%s,Width=%s\n",mxmlElementGetAttr(node,"Height"),mxmlElementGetAttr(node,"Width"));
	node = mxmlFindElement(tree,tree,"ObjectList",NULL,NULL,MXML_DESCEND);
	printf("	ObjectList:Count:%s\n",mxmlElementGetAttr(node,"Count"));
	node = mxmlFindElement(tree,tree,"zOrder",NULL,NULL,MXML_DESCEND);
	printf("	zOrder:%d\n",node->child->value.integer);
	node = mxmlFindElement(tree,tree,"Type",NULL,NULL,MXML_DESCEND);
	printf("	Type:%s\n",node->child->value.text.string);
	node = mxmlFindElement(tree,tree,"Start",NULL,NULL,MXML_DESCEND);
	printf("	Start:X=%s,Y=%s,order=%s\n",mxmlElementGetAttr(node,"X"),mxmlElementGetAttr(node,"Y"),mxmlElementGetAttr(node,"order"));
	node = mxmlFindElement(tree,tree,"End",NULL,NULL,MXML_DESCEND);
	printf("	End:X=%s,Y=%s,order=%s\n",mxmlElementGetAttr(node,"X"),mxmlElementGetAttr(node,"Y"),mxmlElementGetAttr(node,"order"));
	node = mxmlFindElement(tree,tree,"Color",NULL,NULL,MXML_DESCEND);
	printf("	Color:%s\n",node->child->value.text.string);
	node = mxmlFindElement(tree,tree,"PenWidth",NULL,NULL,MXML_DESCEND);
	printf("	PenWidth=%s\n",node->child->value.text.string);
	node = mxmlFindElement(tree,tree,"FillColor",NULL,NULL,MXML_DESCEND);
	printf("	FillColor:%s\n",node->child->value.text.string);
	node = mxmlFindElement(tree,tree,"Name",NULL,NULL,MXML_DESCEND);
	printf("	Name:%s\n",node->child->value.text.string);

	system("pause");

    return 0 ;
}

以上为本人对于minixml的粗浅见解,错漏之处,敬请指出

本人测试minixml代码及英文指南,可自行下载,如果需要的话

http://download.csdn.net/detail/twinkling_z/9437519

你可能感兴趣的:(xml,C)