C++BUILDER 用native xml编写文件问题
怎么在UTF-8的字符集下显示汉字,已经解决了,但是如果是这样应该怎么解决?
TNativeXml *ADoc;
TXmlNode *node;
ADoc = new TNativeXml("Root");
try
{
ADoc->XmlFormat = xfReadable;
ADoc->VersionString="1.0";
ADoc->ExternalEncoding=seUTF8;
ADoc->EncodingString="UTF-8";
node = ADoc->Root->NodeNew("Customer");
node->WriteAttributeString("Sex","男");// 就是这里!改为可以添加汉字属性
node->WriteWidestring("Name", WideString("乔丹"));
ADoc->SaveToFile("c:\\test.xml");
}
__finally
{
ADoc->Free();
}
我如果想在节点中添加汉字属性,一次加入多个属性,怎么实现? 效果:<Information name="张三",sex="男"/>
[最优解释]
//AttributeValueAsWidestring
void __fastcall TForm1::Button6Click(TObject *Sender)
{
TNativeXml *ADoc;
TXmlNode *node;
ADoc = new TNativeXml("Root");
try
{
ADoc->Utf8Encoded = true;
ADoc->XmlFormat = xfReadable;
ADoc->VersionString="1.0";
ADoc->ExternalEncoding=seUTF8;
ADoc->EncodingString="utf-8";
node = ADoc->Root->NodeNew("Customer");
node->WriteAttributeString("Sex","");// 就是这里!改为可以添加汉字属性
node->AttributeValueAsWidestring[0] ="男";
node->WriteWidestring("Name", WideString("乔丹"));
ADoc->SaveToFile("test.xml");
}
__finally
{
ADoc->Free();
}
}