QT5.3中使用tinyXML解析xml文件,获取到的汉语言内容是乱码
QT5.3中使用tinyXML解析xml文件,获取到的中文内容是乱码
如题。
用QT写的一个dll。 dll中的一个内容,就是使用tinyXML读取解析xml文件。
xml文件头 <?xml version="1.0" encoding="gb2312" ?>
部分调用代码:
TiXmlDocument* xmlDoc = new TiXmlDocument();
TiXmlElement* rootElement = NULL; // 根节点
TiXmlElement* VersionAttributeElement = NULL; //VersionAttribute 节点
bool bRet = xmlDoc->LoadFile(szFileName);
if(bRet == false)
return ;
rootElement = xmlDoc->RootElement();
if(rootElement == NULL)
return ;
VersionAttributeElement = rootElement->FirstChildElement();
TiXmlAttribute* attributeOfVersion = VersionAttributeElement->FirstAttribute(); //note
QString VersionNote = attributeOfVersion->Value();
大概是这样,attributeOfVersion->Value(); 对应的xml内容是中文的话,解析后读取到的VersionNote就是“?????”这种情况。
QTextCodec的方法我试过,没什么效果。
------解决思路----------------------
既然你在Qt中,就放弃tinyXml吧,对中文支持很烂,用QXmlStreamReader吧。
如题。
用QT写的一个dll。 dll中的一个内容,就是使用tinyXML读取解析xml文件。
xml文件头 <?xml version="1.0" encoding="gb2312" ?>
部分调用代码:
TiXmlDocument* xmlDoc = new TiXmlDocument();
TiXmlElement* rootElement = NULL; // 根节点
TiXmlElement* VersionAttributeElement = NULL; //VersionAttribute 节点
bool bRet = xmlDoc->LoadFile(szFileName);
if(bRet == false)
return ;
rootElement = xmlDoc->RootElement();
if(rootElement == NULL)
return ;
VersionAttributeElement = rootElement->FirstChildElement();
TiXmlAttribute* attributeOfVersion = VersionAttributeElement->FirstAttribute(); //note
QString VersionNote = attributeOfVersion->Value();
大概是这样,attributeOfVersion->Value(); 对应的xml内容是中文的话,解析后读取到的VersionNote就是“?????”这种情况。
QTextCodec的方法我试过,没什么效果。
------解决思路----------------------
既然你在Qt中,就放弃tinyXml吧,对中文支持很烂,用QXmlStreamReader吧。