Android SAX Parsing: how to save newlines using CDATA tag

I have an Android app that uses SAX parsers to extract data from an XML file. Some data is in some CDATA tags and sometimes contains newline characters. These newlines are removed during parsing. How to save them?

By the way, I thought I found here but putting "& #xA;" inside the CDATA tag will only get "& #xA;" when I take it apart.

Does anyone have any suggestions?

Thanks.

+4
source share
1 answer

Linear translations are not deleted by the parser, regardless of whether they are regular characters or in the CDATA section. But in both cases, various line feeds (Unix, Windows, Mac) are normalized to a single-character canonical ("unix", \ n) line feed. It is impossible to prevent this normalization, with the exception of using a character entity as suggested; and this cannot be done in the CDATA section because data processing is disabled there.

But why exactly do you want to prevent this normalization? If you want this to display, you can simply replace \ n with any local translation line (\ r for mac or \ r \ n for windows).

+2
source

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


All Articles