用CMarkup类,读入XML文件,读入的中文为乱码,请问怎样解决?

laohubinbin 2007-05-08 09:04:54
谢谢
...全文
694 7 打赏 收藏 转发到动态 举报
写回复
用AI写文章
7 条回复
切换为时间正序
请发表友善的回复…
发表回复
yqmfly 2011-08-31
  • 打赏
  • 举报
回复
看看这篇文章的方法是否对你有用,我曾经用这个方法解决过。
http://blog.163.com/lvan100@yeah/blog/static/6811721420115134953280/
还有这个方法,http://zhanyonhu.blog.163.com/blog/static/16186044200921742521746/
ToperRay 2007-05-09
  • 打赏
  • 举报
回复
bool Load( LPCTSTR szFileName );

你用这个函数

或者

改这块

// Windows Unicode file is detected if starts with FEFF
if ( pBuffer[0] == 0xff && pBuffer[1] == 0xfe )
{
// Contains byte order mark, so assume wide char content
// non _UNICODE builds should perform UCS-2 (wide char) to UTF-8 conversion here
csText = (LPCWSTR)(&pBuffer[2]);
csNotes += _T("File starts with hex FFFE, assumed to be wide char format. ");
}
else
{
// _UNICODE builds should perform UTF-8 to UCS-2 (wide char) conversion here
csText = (LPCSTR)pBuffer;
}

这里,UTF-8的解码过程是错误的
paradise099 2007-05-08
  • 打赏
  • 举报
回复
你看看你的XML文件的编码方式,以及你文件存储的方式是否正确。
paradise099 2007-05-08
  • 打赏
  • 举报
回复
这个问题我也遇到过,你看看
蒋晟 2007-05-08
  • 打赏
  • 举报
回复
不要一贴多发
laohubinbin 2007-05-08
  • 打赏
  • 举报
回复
我是这样读取的:
CString csFilename =_T("information.xml") ;

CString csText;
CString csNotes;
CFile file;
if ( ! file.Open( csFilename, CFile::modeRead ) )
{
AfxMessageBox(_T("unable to open file"));
return;
}
int nFileLen = (int)file.GetLength();

// Allocate buffer for binary file data
unsigned char* pBuffer = new unsigned char[nFileLen + 2];
nFileLen = file.Read( pBuffer, nFileLen );
file.Close();
pBuffer[nFileLen] = '\0';
pBuffer[nFileLen+1] = '\0'; // in case 2-byte encoded

// Windows Unicode file is detected if starts with FEFF
if ( pBuffer[0] == 0xff && pBuffer[1] == 0xfe )
{
// Contains byte order mark, so assume wide char content
// non _UNICODE builds should perform UCS-2 (wide char) to UTF-8 conversion here
csText = (LPCWSTR)(&pBuffer[2]);
csNotes += _T("File starts with hex FFFE, assumed to be wide char format. ");
}
else
{
// _UNICODE builds should perform UTF-8 to UCS-2 (wide char) conversion here
csText = (LPCSTR)pBuffer;
}
delete [] pBuffer;

// If it is too short, assume it got truncated due to non-text content
if ( csText.GetLength() < nFileLen / 2 - 20 )
{
AfxMessageBox( _T("Error converting file to string (may contain binary data)") );
return;
}

// Parse
CMarkup xml;
BOOL bResult = xml.SetDoc( csText );
while ( xml.FindChildElem(_T("DrawingInfo")) )
{
xml.IntoElem();
while (xml.FindChildElem( _T("ID") ))
{
xml.IntoElem();
CString tmpStr;
tmpStr=xml.GetAttrib(_T("DrawingID")) ;
m_myDialogBarLeft.SetDlgItemText(IDC_STATIC_DRAWING_ID, tmpStr);
xml.OutOfElem();
}
while (xml.FindChildElem( _T("Name") ))
{
xml.IntoElem();
CString tmpStr;
tmpStr=xml.GetAttrib(_T("DrawingName"));
m_myDialogBarLeft.SetDlgItemText(IDC_STATIC_DRAWING_NAME, tmpStr);
xml.OutOfElem();
}
xml.OutOfElem();
}

当读到“我爱祖国”时就为乱码了,tmpStr显示为“磽 b蚖羱'hWm”的乱码
laohubinbin 2007-05-08
  • 打赏
  • 举报
回复
就是这个文件:
<?xml version='1.0' encoding='UTF-8' standalone='no'?><drawinginformation version="1.0">
<OriginalInfo>
<ID ProcessID="1001"/>
</OriginalInfo>
<DrawingInfo>
<ID DrawingID="00175773"/>
<Name DrawingName="我爱祖国"/>
<Address DrawingAddress="23"/>
</DrawingInfo>
<HouseInfo>
<ID HouseID="0123"/>
<Name HouseName="405号"/>
<Direction HouseDirection="西南"/>
<Code HuxingCode="24"/>
<Name HuxingName="2LDK"/>
<Code HuxingTumianCode="230123456789"/>
<erea HuxingTumianerea="60.00"/>
<tieshu HuxingTumiantieshu="18.15"/>
</HouseInfo>
<Operator>
<Code OperatorCode="0102"/>
<Name OperatorName="某人"/>
</Operator>
<XMLData>
<path path="\\192.168.1.159\d:\间取\间取图xml"/>
<Name FileName="0"/>
</XMLData>
<XMLInfo>
<path path="\c:\间取\间取情报xml"/>
<Name FileName="info_in.xml"/>
</XMLInfo>
<JPGNewFile>
<path path="\\192.168.1.159\画像\公开画像\23"/>
<FileName File1Name="0"/>
</JPGNewFile>
<EPSFileWin>
<path path="\\192.168.1.159\画像\印刷画像\epswin"/>
<FileName FileName="0"/>
</EPSFileWin>
<EPSFileMac>
<path path="\\192.168.1.159\画像\印刷画像\epsmac"/>
<FileName FileName="0"/>
</EPSFileMac>
<PHOTOFile>
<path path="\\192.168.1.159\室内写真"/>
<FileName FileName="0"/>
</PHOTOFile>
<JPGOldFile>
<path path="\\192.168.1.159\画像\公开画像\23"/>
<FileName File1Name="230123456789.jpg"/>
</JPGOldFile>
</drawinginformation>
源码链接: https://pan.quark.cn/s/a4b39357ea24 在本研究中,我们将详细研究如何借助Python执行数据可视化,旨在剖析2018年期间中国四个主要城市——北京、上海、广州以及深圳的空气质量状况。通过绘制反映空气质量指数(AQI)与细颗粒物(PM2.5)变化趋势的图表,我们能够深入理解这些大都市全年的空气环境质量,并明确评估其优良天气所占的比重。 我们必须首先进行数据准备工作。在当前提供的压缩文件内,名为"2018天气"的文件极有可能是数据来源,其中可能收录了涉及四个城市每日空气质量监测的详细信息。这些数据通常涵盖日期、城市名称、AQI数值、PM2.5含量等核心参数。在Python编程环境中,我们惯常运用pandas库来对这结构化数据进行高效的处理和分析。 1. **数据导入与初步处理**: - 利用`pandas.read_csv()`方法来导入存储为CSV格式的数据资料。 - 数据整理:对数据中的空白项、非正常数值进行修正,保证数据的精确性。 - 调整日期字段的格式,确保其能够适用于时间序列分析的需求。 2. **数据深度分析**: - 针对每个城市的AQI和PM2.5数据执行统计性描述,例如计算平均值、中位数、标准偏差等指标。 - 确定空气质量良好天气的天数,即那些AQI值低于75(依据中国的空气质量评估标准)的日数。 3. **数据呈现**: - 运用matplotlib或seaborn工具绘制折线图,直观展示四个城市在2018年全年的AQI和PM2.5变化动态。 - 可通过采用不同的颜色方案和线条型来区分不同城市的数据系列。 - 添加必要的图示元素,如日期坐标轴、城市名称标注、图表标题及图例说明,以提升图表的可读...

3,056

社区成员

发帖
与我相关
我的任务
社区描述
VC/MFC HTML/XML
社区管理员
  • HTML/XML社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧