使用 ACEXML 来解析一个 xml 文件

本段代码通过ACEXML来解析一个XML文件,并且生成了一棵树,树的存储采用孩子兄弟存储的方法。

在连接生成可执行文件的时候,连接一下文件:


ACEd.lib
ACEXMLd.lib
ACEXML_Parserd.lib
iphlpapi.lib


CTree


#pragma once

#include "string"

using namespace std;

class CTree
{
public:
	typedef enum{LEAF = 0x00, NOTLEAF = 0x01} ATTRIBUTE;
public:
	CTree(void);
	CTree(ATTRIBUTE attribute, string value);
	~CTree(void);
private:
	ATTRIBUTE m_attribute;
	string	m_value;
	CTree*	m_left;
	CTree*	m_right;
public:
	void addnode(CTree* children);
	void output(int indent);
	ATTRIBUTE getattribute();
	string getvalue();
	CTree* getleft();
	CTree* getright();
	int getchildnumber();
	CTree* getfirstchild();
	CTree* getnextchild();
	CTree* getchild(int index);
	void destroy();
};


#include "Tree.h"


CTree::CTree(void)
{
	m_attribute = NOTLEAF;
	m_value = "";
	m_left = NULL;
	m_right = NULL;
}

	
CTree::CTree(ATTRIBUTE attribute, string value)
{
	m_attribute = attribute;
	m_value = value;
	m_left = NULL;
	m_right = NULL;
}


CTree::~CTree(void)
{	
	printf("destroy value=%s\n", m_value.c_str());
}


CTree::ATTRIBUTE CTree::getattribute()
{
	return m_attribute;
}

CTree* CTree::getleft()
{
	return m_left;
}

CTree* CTree::getright()
{
	return m_right;
}

string CTree::getvalue()
{
	return m_value;
}

void CTree::destroy()
{	
	if (m_left != NULL)
	{
		m_left->destroy();
	}
	if (m_right != NULL)
	{
		m_right->destroy();
	}
	delete this;
}

void CTree::addnode(CTree* child)
{
	if (m_left == NULL)
	{
		m_left = child;
	}
	else
	{
		CTree* ptemp = m_left;	
		while(ptemp->m_right != NULL)
		{
			ptemp = ptemp->m_right;
		}
		ptemp->m_right = child;
	}
}

void CTree::output(int indent)
{
	//printf("value=%s attri=%c this=%08X left=%08X right=%08X\n", m_value.c_str(), ((m_attribute ==  LEAF) ? 'C' : 'P'), this, m_left, m_right);
	//printf("%s(deep=%d)\n", m_value.c_str(), indent);
	printf("%s\n", m_value.c_str());

	if (m_left != NULL)
	{	
		indent++;
		for(int i=0; i<indent; i++)
		{
			printf("|____");
		}
		m_left->output(indent);	
		indent--;
	}

	if (m_right != NULL)
	{	
		for(int i = 0; i < indent; i++)
		{
			printf("|____");
		}
		m_right->output(indent);
	}
}


int CTree::getchildnumber()
{
	int number = 0;
	if (m_left == NULL)
	{
		return number;
	}
	else 
	{
		number++;
		CTree* temp = m_left;
		while(temp->m_right != NULL)
		{
			number++;
			temp = temp->m_right;
		}
	} 
	return number;
}

CTree* CTree::getfirstchild()
{
	return m_lef
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值