Search code examples
javaandroidxmlparsingsax

SAX Parser, new lines being removed after parsing, can I keep them in? (
)


I'm unsure on how complicated or easy this issue might be since this is my first project with XML parsing and therefore using the SAX parser.

When pulling down XML from a server, I can see in the XML there are a few 
 in the text, a carriage return character, or new line. After the XML has gone through the SAX parser it comes out the other end without those characters.

It comes out as a string and when I add it to a TextView it's just one big block of text, which is obviously not something I want.

Is there a way for me to parse the XML and still keep the 
 characters? My idea was to do a String.replace("
", "\n"); right before adding it to the TextView, therefore making use of new lines.

If there is a better way I would love to know but just being able to use 
 would be helpful too.

Thanks in advance for any advice you can offer.


Solution

  • Before starting the parser I am converting my HTTP result into a string, so before I parse I do a String.replace("
", "
");

    After parsing new lines show up correctly. I guess the parser ignores carriage return in favour or new lines. Which makes sense I guess.

    Hopefully this helps someone down the line.