/** * New in v2.12 * This method will take a segment descriptor and return a new descriptor that removes * all the leading and trailing white spaces around the input segment * * @param l upper 32 bits length of the segment, lower 32 bits offset of the segment, unit in byte * @return a long 64 bit segment descriptor */ final public long trimWhiteSpaces(long l){ return trimWhiteSpaces(l,VTDNav.WS_BOTH); }
/** * Trim whitespaces surrounding the segment */ public final void trimWhiteSpaces(){ vn.trimWhiteSpaces(l); } /**
/** * Trim whitespaces surrounding the segment, could be leading, trailing or both * @param actionType VTDNav.WS_LEADING VTDNav.WS_TRAILING VTDNav.WS_BOTH * public final short VTDNav.WS_LEADING=0; * public final short VTDNav.WS_TRAILING=1; * public final short VTDNav.WS_BOTH=2; */ public final void trimWhiteSpaces(short actionType){ vn.trimWhiteSpaces(l,actionType); }
import com.ximpleware.*; public class removeWS { public static void main(String[] s) throws VTDException, Exception{ VTDGen vg = new VTDGen(); AutoPilot ap = new AutoPilot(); XMLModifier xm = new XMLModifier(); if (vg.parseFile("d:\\xml2\\ws.xml", true)){ VTDNav vn = vg.getNav(); ap.bind(vn); xm.bind(vn); ap.selectXPath("//text()"); int i=-1; while((i=ap.evalXPath())!=-1){ int offset = vn.getTokenOffset(i); int len = vn.getTokenLength(i); long l = vn.trimWhiteSpaces((((long)len)<<32)|offset ); System.out.println(" ===> "+vn.toString(i)); System.out.println("len ==>"+len+" new len==>"+ (l>>32)); int nlen = (int)(l>>32); int nos= (int) l; xm.updateToken(i,vn,nos,nlen); } xm.output("d:\\xml2\\new.xml"); } } }