简体   繁体   中英

Parsing XML file with IXMLDocument in Delphi

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?

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM