Is there a way to get \ r (carriage return) from an XML file without conversion?

The XML specification states that this should be the behavior for processing any "external parsed object." But does this apply to CDATA sections inside an element? What for? Is there a way to get \ r without conversion by adding 1/2 conditions to the parser code, instead of changing \r to 

+4
source share
2 answers

It really is. What for? This simplifies the life of applications that will process the output from an XML file - they just do not need to worry about the format in which newlines are used, increasing application compatibility (let's consider the compatibility of simple text editors between Linux and Windows - they almost always display files incorrectly, on Windows, most often as a single line).

Of course, if for some reason you need to have \ r unconverted, then just take any existing XML parser implementation and modify it. In tinyxml you need to change the function TiXmlBase :: ReadText (), or you can take its older version, as it left unused spaces.

On the other hand, from a design point of view, it would be much easier to just start the parser output through the character replacement function and replace all "\ n" with "\ r \ n".

Of course, it would be best to just use the output as is, right now I can not imagine a single scenario where it would be necessary.

+2
source

CDATA did not name character data for anything. The only elegant way to handle the situation is to encode Base64.

Base64 encodes all 255 possible characters in 64 print characters. To get 255 possibilities in 64 options, the text is a little more, but this will be your only option, except changing your XML layout to something like

 <TEXT> <CHAR>13</CHAR> <CHAR>255</CHAR> </TEXT> 

But in my opinion, this is even worse than &#13; . Now you get.

http://www.ibm.com/developerworks/xml/library/x-cdata/ Visit this site for more information on working with binary data in your XML.

Hope this helps you.

+1
source

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


All Articles