Preserve newlines when parsing xml

后端 未结 2 2092
野趣味
野趣味 2021-01-22 04:18

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条回答
  • 2021-01-22 04:50

    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]);
    
      } 
    
    0 讨论(0)
  • 2021-01-22 04:58

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

    0 讨论(0)
提交回复
热议问题