0

I have a "parse_error" when I try to parse an xml file containing a specific Japanese kanji:

退

If I change this Kanji to another, the parsing works well.

Any idea?

PS: I parse the file with rapidXML

Here is a sample of the xml file:

<?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>
Rodrigue Rens
  • 237
  • 3
  • 7
  • 1
    Is the XML UTF-8? If it's UTF-16 or 32, RapidXml has some issues with those ones, which you can [read about here](http://rapidxml.sourceforge.net/manual.html#namespacerapidxml_1character_types_and_encodings). Make sure your document is encoded in such a way that RapidXml supports, and revise your question to contain details about the XML document's encoding. – Cornstalks Apr 20 '12 at 15:58
  • Yes, the xml is in UTF-8. I will attach the xml document on monday. – Rodrigue Rens Apr 20 '12 at 19:38
  • RapidXML has no problem with this XML if it's correctly UTF-8 encoded. Show your code, as I expect the issue is in how you're using Rapidxml. – Roddy Oct 06 '16 at 12:01

1 Answers1

0

Here actually issue is not with rapidXML library. Issue might be with basic_ifstream.basic_ifstream by defualt opens file in ansi mode only. So we have to set it to utf-8. Use below code snippet:

    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());
  • This is wrong, on a couple of levels: OP is using UTF-8, not UTF-16 or 32. UTF-8 (and thus all unicode code points including Japanese, Chinese etc.) is fully supported by rapidxml, so there's no need to use a different library. – Roddy Oct 06 '16 at 11:58
  • Yes you are right Roddy. Actually i found root cause of this issue. Issue is not with rapidxml library. In my case issues was in basic_ifstream. By default basic_ifstream opens file in ansi mode only. So we need open it in utf-8 mode. – Jayesh Vaghasiya Nov 14 '16 at 12:19
  • Add below lines of code in you existing stream. std::locale loc(std::locale::classic(), new std::codecvt_utf8); XMLFileStream.imbue(loc); – Jayesh Vaghasiya Nov 14 '16 at 12:21