XML UTF8


int _tmain(int argc, _TCHAR* argv[])
{
 USES_CONVERSION;
 FILE* pf = _wfopen(L"w.xml",L"r");

 CHAR buf[1024]={0};
 int r = fread(buf,sizeof(CHAR),sizeof(buf),pf);

 TiXmlDocument doc;
 doc.Parse(buf,0,TIXML_ENCODING_UTF8);
 TiXmlElement* pPluginRoote = doc.RootElement()->FirstChildElement("Policy");

 

 std::string UTF8SZ;
 UTF8SZ << doc;

 TiXmlDocument doc2;
 char* A = UTF82A(buf+3);
 char* AA = UTF82A(A);
 char* UTF8 = UTF82A(A);
 doc2.Parse(A,0,TIXML_ENCODING_LEGACY);

 TiXmlElement* pPluginRoot = doc.RootElement()->FirstChildElement("Policy");
 const char* name = pPluginRoot->Attribute("name");
 const char* nameA =UTF82A(name);
 
 TiXmlElement* pPluginRoot2 = doc2.RootElement()->FirstChildElement("Policy");
 const char* name2 = pPluginRoot2->Attribute("name");
 
 pPluginRoote->SetAttribute("name",name2);
 
 FILE* pfU = _wfopen(L"wU.xml",L"w");
 fwrite(UTF8SZ.c_str(),sizeof(CHAR),UTF8SZ.length(),pfU);
 fclose(pf);

 fclose(pfU);

 return 0;
}

posted @ 2012-07-13 17:50  ahuo  阅读(393)  评论(0编辑  收藏  举报