分类: C/C++
2008-04-02 14:54:23
//得到节点值(长整型)
long GetLong(const char* cstrBaseKeyName, const char* cstrValueName, long lDefaultValue);
//设置节点值(长整型)
long SetLong(const char* cstrBaseKeyName, const char* cstrValueName, long lValue);
//得到节点值(字符串)
std::string GetString(const char* cstrBaseKeyName,
const char* cstrValueName,
const char* cstrDefaultValue);
//设置节点值(字符串)
long SetString(const char* cstrBaseKeyName, const char* cstrValueName, const char* cstrValue);
//得到节点属性
std::string GetAttribute(const char* cstrBaseKeyName, const char* cstrValueName,
const char* cstrAttributeName, const char* cstrDefaultAttributeValue);
//设置节点属性
long SetAttribute(const char* cstrBaseKeyName, const char* cstrValueName,
const char* cstrAttributeName, const char* cstrAttributeValue);
//得到节点值
long GetNodeValue(const char* cstrBaseKeyName, const char* cstrValueName,
const char* cstrDefaultValue, std::string& strValue, const char* cstrAttributeName,
const char* cstrDefaultAttributeValue,std::string& strAttributeValue);
//设置节点值
long SetNodeValue(const char* cstrBaseKeyName, const char* cstrValueName,
const char* cstrValue=NULL, const char* cstrAttributeName=NULL,
const char* cstrAttributeValue=NULL);
//删除某节点和其所有子节点
long DeleteSetting(const char* cstrBaseKeyName, const char* cstrValueName);
//得到某节点的子节点的键值
long GetKeysValue(const char* cstrBaseKeyName,
std::map& keys_val);
//得到某节点的子节点的键名
long GetKeys(const char* cstrBaseKeyName,
std::vector& keys);
//保存XML文件
bool save(const char* filename=NULL);
//装载XML文件
bool load(const char* filename, const char* root_name="xmlRoot");
//不保存改变
void DiscardChanges();
//清空内容
void clear();
一个简单的写入、保存例子:CXMLFile xmlFile;
xmlFile.load("file.xml ");
xmlFile.SetLong("Student/情况", "年龄", 24);
xmlFile.SetString("Student /个况", "籍贯", "浙江嵊州");
xmlFile.SetString("Student /个况", "性别", "男");
xmlFile.save();
一个简单的读取例子: CXMLFile xmlFile;
xmlFile.load("file.xml ");
long age= xmlFile.GetLong("Student/个况", "年龄", 25;
std::string strHomeplace =xmlFile.GetString ("Student /个况", "籍贯", "浙江嵊州");
std::string strSex =xmlFile. GetString ("Student /个况", "性别", "男");
CPersistentTreeCtrl类主要有两个成员函数: //load from a XML file bool Load(const char* filename, const char* tree_name="TreeName", bool bImage=false); //save to a XML file bool Save(const char* filename, const char* tree_name="TreeName", bool bImage=false);分别用于保存和装入树的节点,存取的效率可能不高,权作演示吧。