Android SAX Parsing: How to Preserve Newlines from within a CDATA Tag
I have an Android application that uses the SAX parsers to extract data from an XML file. Some of the data is found within some CDATA tags and sometimes contains newline characters. Those newline characters are being removed during parsing. How do I preserve them?
By the way, I thought I found an answer here, but placing "
" inside a CDATA tag will only result in getting a "
" when I parse it.
Does anyon开发者_如何学Pythone have any suggestions?
Thank you.
Linefeeds are not removed by parser, whether they are as regular characters, or within CDATA section. But in both cases, various linefeeds (Unix, Windows, Mac) are normalized into single-character canonical ("unix", \n) linefeed. There is no way to prevent this normalization from happening, except by using character entity like was suggested; and this can not be done in CDATA section because entity handling is disabled there.
But why exactly do you want to prevent this normalization? If you want this for display, you can just replace \n with whatever local linefeed you want (\r for mac, or \r\n sequence for windows).
精彩评论