Preserve newlines when parsing xml

2020-04-17 05:33发布

I'm using the SAX xml parser to parse some xml data which contains newlines. When using Attributes#getValue, the newline data is lost. How can keep the newlines?

2条回答
▲ chillily
2楼-- · 2020-04-17 05:49

you can use this code when getting the String to parse:

  public void characters(char ch[], int start, int length) { 


      for(int i=start; i<length; i++)
      if(!Character.isISOControl(ch[i]))
          content.append(ch[i]);

  } 
查看更多
Ridiculous、
3楼-- · 2020-04-17 05:57

The solution was to use &#xA; instead of \n

查看更多
登录 后发表回答