Parsing XML file with IXMLDocument in Delphi

318 views Asked by At

In Delphi 10 Rio, I use IXMLDocument to parse an XML file.

<?xml version="1.0" encoding="ISO-8859-1" standalone="yes"?><AWXML><ACTION>RECUP<RETOUR>OK</RETOUR><CRITERE><COMPTE></COMPTE><REGROUPEME></REGROUPEME><bas01></bas01></CRITERE><RUBRIQUE><DOC_NOM>TEST110 &#128;</DOC_NOM>

When I do

NomDoc := Node2.ChildNodes['DOC_NOM'].Text;

NomDoc is 'TEST110 ?', but it should be 'TEST110 €'.

Why is this happening, and how do I fix it?

1

There are 1 answers

0
Remy Lebeau On

The Encoding attribute in the XML's prolog specifies the byte encoding of the XML itself, not the charset that the XML's content is to be interpreted in. XML content is always interpreted in Unicode only. Thus &#128; represents Unicode codepoint U+0080, which is a C1 control character that is "only valid in certain contexts in XML 1.0 documents, and whose usage is restricted and highly discouraged."

If you want to use a Euro character, Unicode codepoint U+20AC, in an XML document, you must use either &#8364; or &#x20AC; instead, regardless of the Encoding specified.