Cannot obtain last element fragment (xpath)

Help
MetinH
2009-06-22
2013-05-15
  • MetinH

    MetinH - 2009-06-22

    Hi,

    I'm trying to split an xml document using xpath. Everything appears to work until I get to the last fragment and I receive the following exception:
    java.lang.IndexOutOfBoundsException

    Here is my code:
    /**
    *
    */
    package com.ussco.syndication.splitter;

    import java.io.File;
    import java.io.FileOutputStream;

    import com.ximpleware.AutoPilot;
    import com.ximpleware.ElementFragmentNs;
    import com.ximpleware.FastLongBuffer;
    import com.ximpleware.VTDGen;
    import com.ximpleware.VTDNav;

    /**
    * @author HAMIDOM
    *
    */
    public class SplitterTest2 {
        private String syncOutputFile = "C:/metin/POC/individual_items/out/SyncItemMaster-small.xml";
       
        public void split() throws Exception {
                        VTDGen vg = new VTDGen();
                       
                        if (vg.parseFile(syncOutputFile,true)){
                           
                            AutoPilot ap = new AutoPilot();
                            VTDNav vn = vg.getNav();
                            ap.bind(vn);
                            ap.declareXPathNameSpace("us", "http://www.ussco.com/oagis/0");
                            ap.declareXPathNameSpace("oa", "http://www.openapplications.org/oagis/9");
                            ap.selectXPath("/us:SyncItemMaster/us:DataArea/us:ItemMaster");
                           
                            FastLongBuffer flb = new FastLongBuffer(4);
                            byte[] xml = vn.getXML().getBytes();

                            int result = -1;
                           
                            while((result=ap.evalXPath())!=-1){
                              
                                try {
                                    ElementFragmentNs fragment = vn.getElementFragmentNs();
                                    long offsetLen = fragment.getOffsetLen();
                                    flb.append(offsetLen);
                                }
                                   catch(IndexOutOfBoundsException e) {
                                       e.printStackTrace();
                                       System.out.println("not good!");
                                       break;
                                   }

                            }
                            ap.resetXPath();

                            int size = flb.size();
                            System.out.println("size: " + size);
                            if (size != 0){
                               
                                for (int k = 0;k<size; k++){
                                    File fo = new File("C:/metin/POC/individual_items/out/2/"+ k + ".xml");
                                    FileOutputStream fos = new FileOutputStream(fo);
                                    fos.write(xml, flb.lower32At(k), flb.upper32At(k));
                                    fos.close();
                                }
                            }
                        }

        }
       
        /**
         * @param args
         */
        public static void main(String[] args) {
            SplitterTest2 x = new SplitterTest2();
            long startTime = System.currentTimeMillis();
           
            try {
                System.out.println("Hi");
                x.split();
               
            }
            catch(Throwable t) {
                t.printStackTrace();
            }
            finally {
                System.out.println("Processing time in seconds: " + ((System.currentTimeMillis() - startTime)/1000));
            }

        }

    }

    ************************************************************
    Here is the output:
    Hi
    java.lang.IndexOutOfBoundsException
        at com.ximpleware.FastLongBuffer.longAt(FastLongBuffer.java:303)
        at com.ximpleware.VTDNav.getTokenDepth(VTDNav.java:1232)
        at com.ximpleware.VTDNav.getElementFragment(VTDNav.java:1096)
        at com.ximpleware.VTDNav.getElementFragmentNs(VTDNav.java:978)
        at com.ussco.syndication.splitter.SplitterTest2.split(SplitterTest2.java:42)
        at com.ussco.syndication.splitter.SplitterTest2.main(SplitterTest2.java:80)
    not good!
    size: 5
    Processing time in seconds: 0
    ***************************************************************

    Any ideas? Please let me know if I need to provide any additional information. Thanks in advance for your help!!!!!!

     
    • jimmy zhang

      jimmy zhang - 2009-06-23

      hi, can you check out the latest vtdnav.java from CVS via web interface, this is the problem that has been reported and fixed...

       
    • MetinH

      MetinH - 2009-06-23

      That worked. Thanks!

       
      • jimmy zhang

        jimmy zhang - 2009-06-23

        the bug fix will go out in 2.6, stay tuned if you want a permanent jar and fix

         

Get latest updates about Open Source Projects, Conferences and News.

Sign up for the SourceForge newsletter:





No, thanks