c++builder用native XML编写XML文件 为什么UTF8无法显示汉字,而GB2312下就可以显示?怎么在UTF-8下显示汉字,怎么设置?求解惑.
本帖最后由 linxinghen123 于 2012-11-22 22:27:55 编辑 查了很多资料,但都说的不是很清楚,刚接触C++BUILDER 希望高手指点~谢谢!
简单例子:
TNativeXml *ADoc;
TXmlNode *node;
ADoc = new TNativeXml("Root");
try
{
node = ADoc->Root->NodeNew("Customer");
node->WriteAttributeInteger("ID", 123456);
node->WriteString("Name", 乔丹)
ADoc->XmlFormat = xfReadable;
ADoc->VersionString="1.0";
ADoc->ExternalEncoding=seUTF8;
ADoc->EncodingString="UTF-8";
ADoc->SaveToFile("c:\\test.xml");
}
__finally
{
ADoc->Free();
}
[解决办法]
前面加个L试试,比如
node->WriteString(L"Name",L"乔丹");
[解决办法]
还有这句话ADoc->Utf8Encoded = true;
void __fastcall TForm1::Button5Click(TObject *Sender)
{
TNativeXml *ADoc;
TXmlNode *node;
ADoc = new TNativeXml("Root");
try
{
ADoc->XmlFormat = xfReadable;
ADoc->Utf8Encoded = true;
ADoc->VersionString="1.0";
ADoc->ExternalEncoding=seUTF8;
ADoc->EncodingString="utf-8";
node = ADoc->Root->NodeNew("Customer");
node->WriteAttributeInteger("ID", 123456);
node->WriteWidestring("Name", WideString("乔丹"));
ADoc->SaveToFile("c:\\test.xml");
}
__finally
{
ADoc->Free();
}
}