www.pudn.com > QQ2004_Source_0.01.rar > Element.h


// Element.h: interface for the CElement class. 
// 
////////////////////////////////////////////////////////////////////// 
 
#if !defined(AFX_ELEMENT_H__30C235A7_5FF4_41D9_A2C2_DBF338337D11__INCLUDED_) 
#define AFX_ELEMENT_H__30C235A7_5FF4_41D9_A2C2_DBF338337D11__INCLUDED_ 
 
#if _MSC_VER > 1000 
#pragma once 
#endif // _MSC_VER > 1000 
 
#include  
 
#define MAX_CONTENT_LENGTH 1024 
 
class CElement; 
typedef int(*LPENUM_CALLBACK_FUNC)(CElement* element); 
 
typedef CTypedPtrList CElementList; 
 
class AFX_EXT_CLASS CElement 
{ 
protected: 
	CString m_tag; 
 
	CString m_content; 
	 
	CElement* m_parent; 
	CElementList m_children; 
	 
	int m_level; 
	 
public: 
	CMapStringToString _attribute; 
 
	void setAttribute(LPCTSTR attribute, LPCTSTR value){ 
		_attribute.SetAt(attribute, value); 
	} 
	CString getAttribute(LPCTSTR attribute){ 
		_ASSERTE(attribute != NULL); 
		if (attribute == NULL) 
			return CString(""); 
 
		CString value; 
		_attribute.Lookup(attribute, value); 
		return value; 
	} 
 
	CString getChildContent(LPCTSTR tag){ 
		CString result; 
		CElement *element = GetFirstChildByTag(tag); 
		if (element == NULL) 
			return result; 
		result = element->get_content(); 
		return result; 
	} 
 
	CElement(CElement* parent); 
	virtual ~CElement();  
	virtual void Free(); 
 
	CString get_content(){return m_content;} 
	void set_content(LPCTSTR content){m_content = content;} 
 
	CString get_tag(){return m_tag;} 
	void set_tag(LPCTSTR tag){m_tag = tag;} 
	 
	CElement* get_parent(){return m_parent;} 
	void set_parent(CElement* parent){m_parent = parent;} 
 
	int get_level(){return m_level;} 
	void set_level(int level){m_level = level;} 
 
	int Enumerate(LPENUM_CALLBACK_FUNC pFunc); 
	int BuildElement(CString& xml); 
	 
	int AddChild(CString tag, CString content); 
 
	HRESULT GetChildrenByTag(LPCTSTR tag, CElementList &list); 
	CElement* GetFirstChildByTag(LPCTSTR tag); 
}; 
#endif // !defined(AFX_ELEMENT_H__30C235A7_5FF4_41D9_A2C2_DBF338337D11__INCLUDED_)