1 9 10 package org.dom4j.samples.sax; 11 12 import org.xml.sax.SAXException ; 13 import org.xml.sax.helpers.XMLFilterImpl ; 14 15 21 public class TrimXMLFilter extends XMLFilterImpl { 22 23 public TrimXMLFilter() { 24 } 25 26 public void characters(char[] ch, int start, int length) 27 throws SAXException { 28 int last = start + length; 29 while (start < last && Character.isWhitespace(ch[start])) { 30 start++; 31 length--; 32 } 33 while (length > 0 && Character.isWhitespace(ch[start + length - 1])) { 34 length--; 35 } 36 if (length > 0) { 37 super.characters(ch, start, length); 38 } 39 } 40 41 public void ignorableWhitespace(char[] ch, int start, int length) 42 throws SAXException { 43 } 44 } 45 46 84 | Popular Tags |