/** * Remove a byte segment from XML. * l's upper 32 bits is length in # of bytes * l's lower 32 bits is byte offset * @param l * @throws NavException * @throws ModifyException * */ public void remove(long l) throws NavException,ModifyException{ removeContent((int)l, (int)(l>>32)); }
/** * Remove a byte segment from XML. * l's upper 32 bits is length in # of bytes * l's lower 32 bits is byte offset * @param l * @throws NavException * @throws ModifyException * */ public void remove(long l) throws NavException,ModifyException{ removeContent((int)l, (int)(l>>32)); }
/** * Remove a byte segment from XML. * l's upper 32 bits is length in # of bytes * l's lower 32 bits is byte offset * @param l * @throws NavException * @throws ModifyException * */ public void remove(long l) throws NavException,ModifyException{ removeContent((int)l, (int)(l>>32)); }
case VTDNav.TOKEN_CDATA_VAL: if (encoding < VTDNav.FORMAT_UTF_16BE) removeContent(os - 9, len + 12 ); else removeContent((os - 9)<<1,(len+12)<<1); return; removeContent(os-4, len+7); else removeContent((os-4) << 1, (len+7) << 1); return; removeContent(os, len); else removeContent((os) << 1, (len) << 1); return;
case VTDNav.TOKEN_CDATA_VAL: if (encoding < VTDNav.FORMAT_UTF_16BE) removeContent(os - 9, len + 12 ); else removeContent((os - 9)<<1,(len+12)<<1); return; removeContent(os-4, len+7); else removeContent((os-4) << 1, (len+7) << 1); return; removeContent(os, len); else removeContent((os) << 1, (len) << 1); return;
case VTDNav.TOKEN_CDATA_VAL: if (encoding < VTDNav.FORMAT_UTF_16BE) removeContent(os - 9, len + 12 ); else removeContent((os - 9)<<1,(len+12)<<1); return; removeContent(os-4, len+7); else removeContent((os-4) << 1, (len+7) << 1); return; removeContent(os, len); else removeContent((os) << 1, (len) << 1); return;
/** * Remove an attribute name value pair from the master document. * @param attrNameIndex * */ public void removeAttribute(int attrNameIndex) throws ModifyException{ int type = md.getTokenType(attrNameIndex); if (type != VTDNav.TOKEN_ATTR_NAME&& type != VTDNav.TOKEN_ATTR_NS) throw new ModifyException("token type should be attribute name"); int os1 = md.getTokenOffset(attrNameIndex); int os2 = md.getTokenOffset(attrNameIndex+1); int len2 = md.getTokenLength(attrNameIndex+1); if (encoding < VTDNav.FORMAT_UTF_16BE) removeContent(os1,os2+len2-os1+1); else removeContent(os1<<1,(os2+len2-os1+1)<<1); }
/** * Remove an attribute name value pair from the master document. * @param attrNameIndex * */ public void removeAttribute(int attrNameIndex) throws ModifyException{ int type = md.getTokenType(attrNameIndex); if (type != VTDNav.TOKEN_ATTR_NAME&& type != VTDNav.TOKEN_ATTR_NS) throw new ModifyException("token type should be attribute name"); int os1 = md.getTokenOffset(attrNameIndex); int os2 = md.getTokenOffset(attrNameIndex+1); int len2 = md.getTokenLength(attrNameIndex+1); if (encoding < VTDNav.FORMAT_UTF_16BE) removeContent(os1,os2+len2-os1+1); else removeContent(os1<<1,(os2+len2-os1+1)<<1); }
/** * Remove an attribute name value pair from the master document. * @param attrNameIndex * */ public void removeAttribute(int attrNameIndex) throws ModifyException{ int type = md.getTokenType(attrNameIndex); if (type != VTDNav.TOKEN_ATTR_NAME&& type != VTDNav.TOKEN_ATTR_NS) throw new ModifyException("token type should be attribute name"); int os1 = md.getTokenOffset(attrNameIndex); int os2 = md.getTokenOffset(attrNameIndex+1); int len2 = md.getTokenLength(attrNameIndex+1); if (encoding < VTDNav.FORMAT_UTF_16BE) removeContent(os1,os2+len2-os1+1); else removeContent(os1<<1,(os2+len2-os1+1)<<1); }
removeContent(temp + 1, len); return; removeContent(temp+2, len<<1); } else { removeContent(temp+2 , len<<1);
removeContent(temp + 1, len); return; removeContent(temp+2, len<<1); } else { removeContent(temp+2 , len<<1);
removeContent(temp + 1, len); return; removeContent(temp+2, len<<1); } else { removeContent(temp+2 , len<<1);
/** * Removes content from the master XML document * It first calls getCurrentIndex() if the result is * a starting tag, then the entire element referred to * by the starting tag is removed * If the result is an attribute name or ns node, then * the corresponding attribute name/value pair is removed * If the token type is one of text, CDATA or commment, * then the entire node, including the starting and ending * delimiting text surrounding the content, is removed * */ public void remove() throws NavException,ModifyException{ int i = md.getCurrentIndex(); int type = md.getTokenType(i); if (type==VTDNav.TOKEN_STARTING_TAG){ long l = md.getElementFragment(); removeContent((int)l, (int)(l>>32)); } else if (type == VTDNav.TOKEN_ATTR_NAME || type==VTDNav.TOKEN_ATTR_NS){ removeAttribute(i); } else { removeToken(i); } }
/** * Removes content from the master XML document * It first calls getCurrentIndex() if the result is * a starting tag, then the entire element referred to * by the starting tag is removed * If the result is an attribute name or ns node, then * the corresponding attribute name/value pair is removed * If the token type is one of text, CDATA or commment, * then the entire node, including the starting and ending * delimiting text surrounding the content, is removed * */ public void remove() throws NavException,ModifyException{ int i = md.getCurrentIndex(); int type = md.getTokenType(i); if (type==VTDNav.TOKEN_STARTING_TAG){ long l = md.getElementFragment(); removeContent((int)l, (int)(l>>32)); } else if (type == VTDNav.TOKEN_ATTR_NAME || type==VTDNav.TOKEN_ATTR_NS){ removeAttribute(i); } else { removeToken(i); } }
/** * Removes content from the master XML document * It first calls getCurrentIndex() if the result is * a starting tag, then the entire element referred to * by the starting tag is removed * If the result is an attribute name or ns node, then * the corresponding attribute name/value pair is removed * If the token type is one of text, CDATA or commment, * then the entire node, including the starting and ending * delimiting text surrounding the content, is removed * */ public void remove() throws NavException,ModifyException{ int i = md.getCurrentIndex(); int type = md.getTokenType(i); if (type==VTDNav.TOKEN_STARTING_TAG){ long l = md.getElementFragment(); removeContent((int)l, (int)(l>>32)); } else if (type == VTDNav.TOKEN_ATTR_NAME || type==VTDNav.TOKEN_ATTR_NS){ removeAttribute(i); } else { removeToken(i); } }
import com.ximpleware.*; public class replaceContent { 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:\\xml\\input2.xml", true)){ VTDNav vn = vg.getNav(); ap.bind(vn); xm.bind(vn); ap.selectXPath("/clients/function/block"); int i=-1; byte[] s1 = ("\r\n\t\t<opster>hello = world</opster>\r\n\t\t"+ "<opster>abc = def</opster>\r\n\t").getBytes(); while((i=ap.evalXPath())!=-1){ xm.insertAfterHead(s1); long l= vn.getContentFragment(); // add new stuff after the starting tag xm.removeContent((int)l, (int)(l>>32)); // remove old stuff } xm.output("d:\\xml\\new.xml"); } } }
for (int j=0;j<fib.size();j++){ xm.insertAfterHead(vn,l1); xm.removeContent((int)(l2),(int)(l2>>32)); l3= fib.longAt(j); xm.insertBeforeTail(vn,l3);