Delphi, IXMLDOMDocument2, Download fails due to invalid character

Using Delphi 2009 and IXMLDOMDocument2

When loading XML into an IXMLDOMDocument2 file, the error message "An invalid character was found in text content" appears. Symbol 1B (in Hex) and is present in the CDATA section. The Microsoft XML Viewer (IE) downloads the file just fine. XML looks like ...

<data><child><![CDATA[-- ]]></child></data>

NOTE. I am trying to insert XML, but the special character is deleted. In the CDATA section, there is a 1B character following the "-" in my XML file.

I tried to add the beginning of XML and other encodings, and nothing works for me. Is there anything that can be done to download this file?

Thanks Michael

+3
source share
2 answers

The U + 001B character is not allowed in XML, along with most other ASCII control characters. It is not correct, and if the Microsoft XML Viewer does not complain, it does not parse it in accordance with XML rules. Tsk!

Only in XML 1.1 all documents except U + 0000 can be included in the document as a symbolic link, for example &#x1B;. (Obviously this is not used in the CDATA section, but then the CDATA sections are actually not very useful.)

If you need to include arbitrary control characters in XML, you will usually need to use an application coding scheme such as base64.

+5
source

-, - , &#x0;, XML. , XML WideString, StringReplace() XML IXMLDocument.
, . XML , , .

0

Source: https://habr.com/ru/post/1771966/


All Articles