/** * New in v2.12 * Dump a fragement as specified by a long into an output stream * @param l upper 32 bit is length in byte, lower 32 bit is offset in byte * @param os output stream * @throws NavException * @throws IOException */ final public void dumpFragment(long l, OutputStream os)throws NavException, IOException{ int os1 = (int)l; int len = (int)(l>>32); //File f = new File(fileName); //FileOutputStream fos = new FileOutputStream(f); os.write(this.getXML().getBytes(), os1, len); }
/** * New in v2.12 * Dump an element fragment of xml into an XML file whose name is specified as fileName * @param l upper 32 bits are length in byte, lower 32 bits are offset in byte * @param fileName * @throws NavException * @throws FileNotFoundException * @throws IOException */ final public void dumpFragment(long l,String fileName) throws NavException, FileNotFoundException,IOException{ //long l = getElementFragment(); int os = (int)l; int len = (int)(l>>32); File f = new File(fileName); FileOutputStream fos = new FileOutputStream(f); fos.write(this.getXML().getBytes(), os, len); fos.close(); }
while((i=ap.evalXPath())!=-1){ long l=vn.getElementFragment(); fos.write(vn.getXML().getBytes(), (int)l, (int)(l>>32)); j++; if ((j+1)%2000==0){
import com.ximpleware.*; import java.io.*; public class splitXML { public static void main(String[] args) throws VTDException, IOException { VTDGen vg = new VTDGen(); if (!vg.parseFile("d:\\xml\\input.xml", false)){ System.out.println("error"); return; } VTDNav vn = vg.getNav(); AutoPilot ap = new AutoPilot(vn); ap.selectXPath("/engineers/engineer"); int i=0,n=0; FileOutputStream fos =null; byte[] stag="<engineers>".getBytes(); byte[] etag="</engineers>".getBytes(); while((i=ap.evalXPath())!=-1){ fos.write(stag); fos = new FileOutputStream("d:\\xml\\output"+(++n)+".xml"); long l = vn.getElementFragment(); fos.write(vn.getXML().getBytes(), (int)l, (int)(l>>32)); fos.write(etag); fos.close(); } } }
import com.ximpleware.*; import java.io.FileOutputStream; public class splitTest { public static void main(String[] a) throws VTDException,java.io.IOException{ VTDGen vg = new VTDGen(); if (vg.parseFile("C:\\Users\\Jimmy Zhang\\workspace\\ximple-dev\\DOMTest\\test111.xml", false)){ VTDNav vn = vg.getNav(); AutoPilot ap = new AutoPilot(vn); ap.selectXPath("/CATALOG/MAIN"); byte[] header = "<CATALOG>".getBytes(); byte[] tail = "</CATALOG>".getBytes(); int i = -1,j=0; while((i=ap.evalXPath())!=-1){ long l = vn.getElementFragment(); FileOutputStream fops = new FileOutputStream("c:\\xml\\output"+j+".xml"); fops.write(header); fops.write(vn.getXML().getBytes(), (int)l, ((int)(l>>32))); fops.write(tail); fops.close(); j++; } } } }
import java.io.*; import com.ximpleware.*; public class split { public static void main(String[] argv) throws Exception{ VTDGen vg = new VTDGen(); if (vg.parseFile("c:/split/input.xml", true)){ VTDNav vn = vg.getNav(); AutoPilot ap = new AutoPilot(vn); ap.selectXPath("/a/b"); int i=-1,k=0; byte[] ba = vn.getXML().getBytes(); while((i=ap.evalXPath())!=-1){ FileOutputStream fos = new FileOutputStream("c:/split/out"+k+".xml"); fos.write("<a>".getBytes()); long l = vn.getElementFragment(); fos.write(ba, (int)l, (int)(l>>32)); fos.write("</a>".getBytes()); k++; } } } }
import com.ximpleware.*; import java.io.*; public class splitXML { public static void main(String[] args) throws VTDException, IOException { VTDGen vg = new VTDGen(); if (!vg.parseFile("d:\\xml\\input.xml", false)){ System.out.println("error"); return; } VTDNav vn = vg.getNav(); AutoPilot ap = new AutoPilot(vn); ap.selectXPath("/tagmain/*"); int i=0,n=0; FileOutputStream fos =null; while((i=ap.evalXPath())!=-1){ fos = new FileOutputStream("d:\\xml\\output"+(++n)+".xml"); long l = vn.getElementFragment(); fos.write(vn.getXML().getBytes(), (int)l, (int)(l>>32)); fos.close(); } } }
import com.ximpleware.*; import java.io.*; public class simpleMerge { static VTDGen vg = new VTDGen(); public static void main(String[] s) throws VTDException,IOException{ FileOutputStream fos = new FileOutputStream("d:\\xml\\o.xml"); // write header to byte[] header=("<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n"+ "<products>").getBytes(); fos.write(header); appendSingleFile("d:\\xml\\xml-1.xml",fos); appendSingleFile("d:\\xml\\xml-2.xml",fos); fos.write("</products>".getBytes()); } // write everything under root into output efficiently, ie. direct byte copying public static void appendSingleFile(String fileName,FileOutputStream fos) throws VTDException,IOException{ if (!vg.parseFile(fileName, false)){ System.out.println("invalid file:"+fileName); System.exit(1); } VTDNav vn = vg.getNav(); long l = vn.getContentFragment(); fos.write(vn.getXML().getBytes(),(int)l,(int)(l>>32)); vg.clear(); } }
import com.ximpleware.*; import java.io.*; public class splitXML { public static void main(String[] args) throws VTDException, IOException { VTDGen vg = new VTDGen(); if (!vg.parseFile("d:\\xml\\input.xml", false)){ System.out.println("error"); return; } VTDNav vn = vg.getNav(); AutoPilot ap = new AutoPilot(vn); ap.selectXPath("/tag0/*"); int i=0,n=0; FileOutputStream fos =null; while((i=ap.evalXPath())!=-1){ fos = new FileOutputStream("d:\\xml\\output"+(++n)+".xml"); long l = vn.getElementFragment(); fos.write(vn.getXML().getBytes(), (int)l, (int)(l>>32)); fos.close(); } } }
import com.ximpleware.*; import java.io.*; public class splitXML { public static void main(String[] args) throws VTDException, IOException { VTDGen vg = new VTDGen(); if (!vg.parseFile("d:\\xml\\input.xml", false)){ System.out.println("error"); return; } VTDNav vn = vg.getNav(); AutoPilot ap = new AutoPilot(vn); ap.selectXPath("/add/doc"); int i=0,n=0; FileOutputStream fos =null; while((i=ap.evalXPath())!=-1){ fos = new FileOutputStream("d:\\xml\\output"+(++n)+".xml"); long l = vn.getElementFragment(); fos.write(vn.getXML().getBytes(), (int)l, (int)(l>>32)); fos.close(); } } }
import java.io.FileOutputStream; import com.ximpleware.*; public class split { public static void main(String[] args) throws Exception { VTDGen vg = new VTDGen(); if (vg.parseHttpUrl("c:\\xml\\input.xml", true)) { VTDNav vn = vg.getNav(); AutoPilot ap = new AutoPilot(vn); ap.selectXPath("/records/record"); int i=-1,j=0; while ((i = ap.evalXPath()) != -1) { long l=vn.getElementFragment(); (new FileOutputStream("out"+j+".xml")).write(vn.getXML().getBytes(), (int)l,(int)(l>>32)); j++; } } } }
byte[] xml = vn.getXML().getBytes(); while ((i = ap.evalXPath()) != -1) { flb.append(vn.getElementFragment());
/** * * @param l * @throws ModifyException */ private void insertEndingTag(long l) throws ModifyException{ int i = md.getCurrentIndex(); int offset = md.getTokenOffset(i); int length = md.getTokenLength(i)&0xffff; byte[] xml = md.getXML().getBytes(); if (md.encoding <VTDNav.FORMAT_UTF_16BE ) insertBytesAt((int)l,xml,offset,length); else insertBytesAt((int)l, xml, offset<<1, length<<1); }
/** * * @param l * @throws ModifyException */ private void insertEndingTag(long l) throws ModifyException{ int i = md.getCurrentIndex(); int offset = md.getTokenOffset(i); int length = md.getTokenLength(i)&0xffff; byte[] xml = md.getXML().getBytes(); if (md.encoding <VTDNav.FORMAT_UTF_16BE ) insertBytesAt((int)l,xml,offset,length); else insertBytesAt((int)l, xml, offset<<1, length<<1); }
/** * * @param l * @throws ModifyException */ private void insertEndingTag(long l) throws ModifyException{ int i = md.getCurrentIndex(); int offset = md.getTokenOffset(i); int length = md.getTokenLength(i)&0xffff; byte[] xml = md.getXML().getBytes(); if (md.encoding <VTDNav.FORMAT_UTF_16BE ) insertBytesAt((int)l,xml,offset,length); else insertBytesAt((int)l, xml, offset<<1, length<<1); }
long l = md.getElementFragment(); int encoding = md.getEncoding(); byte[] xml = md.getXML().getBytes(); int temp = (int)l+(int)(l>>32); if (encoding < VTDNav.FORMAT_UTF_16BE) {
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"); } }
int docSize = md.getXML().getBytes().length; int inc = (md.encoding<VTDNav.FORMAT_UTF_16BE)?2:4; long l;
int docSize = md.getXML().getBytes().length; int inc = (md.encoding<VTDNav.FORMAT_UTF_16BE)?2:4; long l;
int docSize = md.getXML().getBytes().length; int inc = (md.encoding<VTDNav.FORMAT_UTF_16BE)?2:4; long l;