Problem Source: http://www.cnblogs.com/del/archive/2011/03/24/1994029.html#2059114
Globe has such an XML file:
<xmp> &lt;? XML version = &quot;1.0&quot; encoding = &quot;gb2312&quot;?&gt; &lt;Root&gt; &lt;friend name = &quot;Ten Years&quot;&gt; &lt;/friend&gt; &lt;friend name = &quot;has been running&quot;&gt; &lt;/friend&gt; &lt;friend name = &quot;too many connections commandid &quot;&gt; &lt;/friend&gt; &lt;/root&gt; </xmp>
It contains Chinese and Korean characters, and some are hexadecimal and some are decimal. The actual content should be:
<xmp> &lt;? XML version = &quot;1.0&quot; encoding = &quot;gb2312&quot;?&gt; &lt;Root&gt; &lt;friend name = &quot;Ten Years&quot;&gt; &lt;/friend&gt; &lt;friend name = &quot;has been running&quot;&gt; &lt;/friend&gt; &lt;friend name = &quot;too many connections commandid &quot;&gt; &lt;/friend&gt; &lt;/root&gt; </xmp>
Below is how to open it and save it as a standard UTF-8 format XMLCode(Use delphixe's latest Regular Expression component ):
Unit unit1; interfaceuses windows, messages, sysutils, variants, classes, graphics, controls, forms, dialogs, stdctrls, regularexpressions; Type tform1 = Class (tform) button1: tbutton; procedure button1click (Sender: tobject); Private function mymatchevaluator (const match: tmatch): string; public end; var form1: tform1; implementation {$ R *. DFM} procedure tform1.button1click (Sender: tobject); const Pattern = '? [0-9a-fa-f] {1, 5}; '; var list: tstringlist; Reg: tregex; Path, tmpname: string; begin with topendialog. create (NiL) Do begin execute; Path: = filename; free; end; If Path = ''then exit; List: = tstringlist. create; List. loadfromfile (PATH); list. text: = stringreplace (list. text, 'gb2312', 'utf-8', [rfignorecase]); Reg: = tregex. create (pattern, [rocompiled]); list. text: = reg. replace (list. text, mymatchevaluator); tmpname: = extractfilename (PATH); Path: = stringreplace (path, tmpname, 'utf8 _ '+ tmpname, [rfignorecase]); text: = path; list. savetofile (path, tencoding. utf8); list. free; end; function tform1.mymatchevaluator (const match: tmatch): string; begin result: = match. groups [1]. value; If match. value [3] = 'X' then result: = '$' + result; Result: = widechar (strtoint (result); end.