使用 RapidXML 解析 Xml 文件时出错

Error while parsing a Xml file with RapidXML

本文关键字:出错 文件 Xml RapidXML 解析 使用      更新时间:2023-10-16

当我尝试解析包含特定日语汉字的 xml 文件时,我有一个"parse_error":

退

如果我将此汉字更改为另一个汉字,则解析效果很好。

知道吗?

PS:我用快速XML解析文件

下面是 xml 文件的示例:

<?xml version="1.0" encoding="UTF-8"?>
<Root xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="Exam.xsd">
    <Patient>
     <ESUID>CRodrigueTest-20120423-104410</ESUID>
     <Lastname>退</Lastname>
    </Patient>
</Root>

这里实际上问题不是 rapidXML 库。问题可能与 basic_ifstream.basic_ifstream 有关,因为 defualt 仅在 ansi 模式下打开文件。所以我们必须将其设置为 utf-8。使用以下代码片段:

    basic_ifstream<wchar_t> fFileStream(fullxmlfilepath, ios::binary);
    std::locale loc(std::locale::classic(), new std::codecvt_utf8<wchar_t>);
    fFileStream.imbue(loc);  
    xmlFile = new rapidxml::file<wchar_t>(fFileStream);
    doc.parse<parse_declaration_node>(xmlFile ->data());