通过写xml配置文件方式实现多语言
--------------------------------------------------------------------------------
那就把字符串资源放在xml文件中,载入字符串的时候从xml读取
--------------------------------------------------------------------------------
读取xml文件
--------------------------------------------------------------------------------
能给个例子么,你们说的我知道
--------------------------------------------------------------------------------
读写XML文件可用MSXML4
//引入
#import "C:\WINNT.0\system32\msxml4.dll"
//DOM的DOC对象定义
MSXML2::IXMLDOMDocumentPtr pXMLDoc;
//解析
void CMainFrame::OnParsexmldoc()
{
//加载文件
pXMLDoc->load("c:\\XML\\test.xml");
//在树中查找名为City的节点,"//"表示在任意一层查找
MSXML2::IXMLDOMElementPtr childNode ;
childNode = (MSXML2::IXMLDOMElementPtr)(pXMLDoc->selectSingleNode("//AUTHOR"));
//得到节点类型
MSXML2::DOMNodeType nodeType;
childNode->get_nodeType(&nodeType);
//节点名称
BSTR var;
CString name;
childNode->get_nodeName(&var);
name = (char*)(_bstr_t)var;
//节点值
VARIANT varVal;
childNode->get_nodeTypedValue(&varVal);
CString strValue = (char*)(_bstr_t)varVal;
//节点属性,放在链表中
MSXML2::IXMLDOMNamedNodeMapPtr pAttrs = NULL;
MSXML2::IXMLDOMNodePtr pAttrItem;
childNode->get_attributes(&pAttrs);
long nCount ;
pAttrs->get_length(&nCount);
for(int i = 0 ; i < nCount ; i++)
{
pAttrs->get_item(i,&pAttrItem);
//我们可以通过函数get_nodeName,get_nodeTypedValue得到属性名和属性值
//也可以直接得到
CString strAttrName = (char*)(_bstr_t)pAttrItem->nodeName;
CString strAttrValue = (char*)(_bstr_t)pAttrItem->nodeTypedValue;
}
}
//创建
void CMainFrame::OnCreatexmldoc()
{
MSXML2::IXMLDOMElementPtr xmlRoot;
//根节点的名称为china
pXMLDoc->raw_createElement((_bstr_t)(char*)"china", &xmlRoot);
//MSXML2::IXMLDOMNamedNodeMapPtr pAttrs = NULL;
//pAttrs->length=2;
//xmlRoot->raw_setAttributeNode(
//xmlRoot->setAttributeNode(attributes.setAttribute("fengjie","fengjie test root attribute");
xmlRoot->setAttribute("fengjie","ddd test root attribute");
pXMLDoc->raw_appendChild(xmlRoot, NULL);
MSXML2::IXMLDOMElementPtr childNode ;
pXMLDoc->raw_createElement((_bstr_t)(char*)"City:dd", &childNode);
childNode->Puttext("WuHan");//节点值
childNode->setAttribute("population","8,000,000");//属性名,属性值
childNode->setAttribute("area","10000");
xmlRoot->appendChild(childNode);
pXMLDoc->raw_createElement((_bstr_t)(char*)"City:xx", &childNode);
childNode->Puttext("ShangHai");
childNode->setAttribute("population","12,000,000");
childNode->setAttribute("area","12000");
xmlRoot->appendChild(childNode);
//保存到文件
//如果不存在就建立,存在就覆盖
pXMLDoc->save("c:\\XML\\he.xml");
}