/** * This method will first call getCurrentIndex() to get the cursor index value * then insert the transcoded representation of a segment of the byte array contained in * vn before the element * l1 (a long)'s upper 32 bit is length, lower 32 bit is offset * @param vn * @param l * @throws ModifyException * @throws UnsupportedEncodingException * @throws TranscodeException * */ public void insertBeforeElement(VTDNav vn, long l) throws ModifyException, UnsupportedEncodingException, TranscodeException { insertBeforeElement(vn.encoding, vn.XMLDoc.getBytes(),l); } /**
/** * This method will first call getCurrentIndex() to get the cursor index value * then insert the transcoded representation of a segment of the byte array contained * in vn before the element * @param vn * @param contentOffset * @param contentLen * @throws ModifyException * @throws UnsupportedEncodingException * @throws TranscodeException * */ public void insertBeforeElement(VTDNav vn,int contentOffset, int contentLen) throws ModifyException, UnsupportedEncodingException, TranscodeException { insertBeforeElement(vn.encoding, vn.XMLDoc.getBytes(),contentOffset, contentLen); } /**
/** * This method will first call getCurrentIndex() to get the cursor index value * then insert the transcoded representation of a segment of the byte array contained * in vn before the element * @param vn * @param contentOffset * @param contentLen * @throws ModifyException * @throws UnsupportedEncodingException * @throws TranscodeException * */ public void insertBeforeElement(VTDNav vn,int contentOffset, int contentLen) throws ModifyException, UnsupportedEncodingException, TranscodeException { insertBeforeElement(vn.encoding, vn.XMLDoc.getBytes(),contentOffset, contentLen); } /**
/** * This method will first call getCurrentIndex() to get the cursor index value * then insert the transcoded representation of a segment of the byte array contained in * vn before the element * l1 (a long)'s upper 32 bit is length, lower 32 bit is offset * @param vn * @param l * @throws ModifyException * @throws UnsupportedEncodingException * @throws TranscodeException * */ public void insertBeforeElement(VTDNav vn, long l) throws ModifyException, UnsupportedEncodingException, TranscodeException { insertBeforeElement(vn.encoding, vn.XMLDoc.getBytes(),l); } /**
/** * This method will first call getCurrentIndex() to get the cursor index value * then insert the transcoded representation of a segment of the byte array contained * in vn before the element * @param vn * @param contentOffset * @param contentLen * @throws ModifyException * @throws UnsupportedEncodingException * @throws TranscodeException * */ public void insertBeforeElement(VTDNav vn,int contentOffset, int contentLen) throws ModifyException, UnsupportedEncodingException, TranscodeException { insertBeforeElement(vn.encoding, vn.XMLDoc.getBytes(),contentOffset, contentLen); } /**
/** * This method will first call getCurrentIndex() to get the cursor index value * then insert the transcoded representation of a segment of the byte array contained in * vn before the element * l1 (a long)'s upper 32 bit is length, lower 32 bit is offset * @param vn * @param l * @throws ModifyException * @throws UnsupportedEncodingException * @throws TranscodeException * */ public void insertBeforeElement(VTDNav vn, long l) throws ModifyException, UnsupportedEncodingException, TranscodeException { insertBeforeElement(vn.encoding, vn.XMLDoc.getBytes(),l); } /**
/** * This method will first call getCurrentIndex() to get the cursor index value * then insert the transcoded representatin of the byte array b before the element * @param b the byte array to be inserted into the master document * @throws ModifyException * @throws TranscodeException * */ public void insertBeforeElement(int src_encoding, byte[] b) throws ModifyException,TranscodeException{ if (src_encoding == md.encoding) { insertBeforeElement(b); } else { int startTagIndex = md.getCurrentIndex(); int type = md.getTokenType(startTagIndex); if (type != VTDNav.TOKEN_STARTING_TAG) throw new ModifyException("Token type is not a starting tag"); int offset = md.getTokenOffset(startTagIndex) - 1; byte[] bo = Transcoder.transcode(b,0,b.length,src_encoding, encoding); if (encoding < VTDNav.FORMAT_UTF_16BE) insertBytesAt(offset, bo); else insertBytesAt((offset) << 1, bo); } }
/** * This method will first call getCurrentIndex() to get the cursor index value * then insert the transcoded representatin of the byte array b before the element * @param b the byte array to be inserted into the master document * @throws ModifyException * @throws TranscodeException * */ public void insertBeforeElement(int src_encoding, byte[] b) throws ModifyException,TranscodeException{ if (src_encoding == md.encoding) { insertBeforeElement(b); } else { int startTagIndex = md.getCurrentIndex(); int type = md.getTokenType(startTagIndex); if (type != VTDNav.TOKEN_STARTING_TAG) throw new ModifyException("Token type is not a starting tag"); int offset = md.getTokenOffset(startTagIndex) - 1; byte[] bo = Transcoder.transcode(b,0,b.length,src_encoding, encoding); if (encoding < VTDNav.FORMAT_UTF_16BE) insertBytesAt(offset, bo); else insertBytesAt((offset) << 1, bo); } }
UnsupportedEncodingException, TranscodeException { if (src_encoding == encoding) { insertBeforeElement(b,contentOffset, contentLen); } else { int startTagIndex = md.getCurrentIndex();
UnsupportedEncodingException, TranscodeException { if (src_encoding == encoding) { insertBeforeElement(b,contentOffset, contentLen); } else { int startTagIndex = md.getCurrentIndex();
/** * This method will first call getCurrentIndex() to get the cursor index value * then insert the transcoded representatin of the byte array b before the element * @param b the byte array to be inserted into the master document * @throws ModifyException * @throws TranscodeException * */ public void insertBeforeElement(int src_encoding, byte[] b) throws ModifyException,TranscodeException{ if (src_encoding == md.encoding) { insertBeforeElement(b); } else { int startTagIndex = md.getCurrentIndex(); int type = md.getTokenType(startTagIndex); if (type != VTDNav.TOKEN_STARTING_TAG) throw new ModifyException("Token type is not a starting tag"); int offset = md.getTokenOffset(startTagIndex) - 1; byte[] bo = Transcoder.transcode(b,0,b.length,src_encoding, encoding); if (encoding < VTDNav.FORMAT_UTF_16BE) insertBytesAt(offset, bo); else insertBytesAt((offset) << 1, bo); } }
/** * This method will first call getCurrentIndex() to get the cursor index value * then insert the transcoded representation of a segment of the byte array b before the element * l1 (a long)'s upper 32 bit is length, lower 32 bit is offset * @param b * @param l1 * @throws ModifyException * @throws UnsupportedEncodingException * @throws TranscodeException * */ public void insertBeforeElement(int src_encoding, byte[] b, long l1) throws ModifyException, UnsupportedEncodingException, TranscodeException { if (src_encoding == md.encoding) { insertBeforeElement(b, l1); } else { int startTagIndex = md.getCurrentIndex(); int type = md.getTokenType(startTagIndex); if (type != VTDNav.TOKEN_STARTING_TAG) throw new ModifyException("Token type is not a starting tag"); int offset = md.getTokenOffset(startTagIndex) - 1; byte[] bo = Transcoder.transcode(b, (int)l1, (int)(l1>>32),src_encoding, encoding); if (encoding < VTDNav.FORMAT_UTF_16BE) insertBytesAt(offset, bo ); else insertBytesAt((offset) << 1, bo); } }
/** * This method will first call getCurrentIndex() to get the cursor index value * then insert the transcoded representation of a segment of the byte array b before the element * l1 (a long)'s upper 32 bit is length, lower 32 bit is offset * @param b * @param l1 * @throws ModifyException * @throws UnsupportedEncodingException * @throws TranscodeException * */ public void insertBeforeElement(int src_encoding, byte[] b, long l1) throws ModifyException, UnsupportedEncodingException, TranscodeException { if (src_encoding == md.encoding) { insertBeforeElement(b, l1); } else { int startTagIndex = md.getCurrentIndex(); int type = md.getTokenType(startTagIndex); if (type != VTDNav.TOKEN_STARTING_TAG) throw new ModifyException("Token type is not a starting tag"); int offset = md.getTokenOffset(startTagIndex) - 1; byte[] bo = Transcoder.transcode(b, (int)l1, (int)(l1>>32),src_encoding, encoding); if (encoding < VTDNav.FORMAT_UTF_16BE) insertBytesAt(offset, bo ); else insertBytesAt((offset) << 1, bo); } }
/** * This method will first call getCurrentIndex() to get the cursor index value * then insert the transcoded representation of a segment of the byte array b before the element * l1 (a long)'s upper 32 bit is length, lower 32 bit is offset * @param b * @param l1 * @throws ModifyException * @throws UnsupportedEncodingException * @throws TranscodeException * */ public void insertBeforeElement(int src_encoding, byte[] b, long l1) throws ModifyException, UnsupportedEncodingException, TranscodeException { if (src_encoding == md.encoding) { insertBeforeElement(b, l1); } else { int startTagIndex = md.getCurrentIndex(); int type = md.getTokenType(startTagIndex); if (type != VTDNav.TOKEN_STARTING_TAG) throw new ModifyException("Token type is not a starting tag"); int offset = md.getTokenOffset(startTagIndex) - 1; byte[] bo = Transcoder.transcode(b, (int)l1, (int)(l1>>32),src_encoding, encoding); if (encoding < VTDNav.FORMAT_UTF_16BE) insertBytesAt(offset, bo ); else insertBytesAt((offset) << 1, bo); } }
UnsupportedEncodingException, TranscodeException { if (src_encoding == encoding) { insertBeforeElement(b,contentOffset, contentLen); } else { int startTagIndex = md.getCurrentIndex();
xm.insertBeforeElement("<b/>\n\t");
import com.ximpleware.*; import java.io.*; public class removeTag { public static void main(String[] args) throws VTDException,IOException { // TODO Auto-generated method stub VTDGen vg = new VTDGen(); AutoPilot ap=new AutoPilot(); ap.selectXPath("//value"); XMLModifier xm = new XMLModifier(); if (!vg.parseFile("d:\\xml\\tag.xml", false)){ System.out.println("error in xml"); return; } VTDNav vn = vg.getNav(); xm.bind(vn); ap.bind(vn); int i=0; while((i=ap.evalXPath())!=-1){ xm.remove();//remove value fragment long l = vn.getContentFragment(); //replace value with everything it encloses xm.insertBeforeElement(vn.getXML().getBytes(), l); } xm.output("d:\\xml\\newTag.xml"); } }