質問

To execute a XPATH query in huge xml file I read many articles that prefere VTD-XML to does it so I copied this code which was in those articles :

import com.ximpleware.extended.*;
public class MainVTD {
    public static void main(String[] s) throws Exception{
        VTDGenHuge vg = new VTDGenHuge();
        if (vg.parseFile("./resource/init/dblp_3.xml",true,VTDGenHuge.MEM_MAPPED)){
            VTDNavHuge vnh = vg.getNav();
            AutoPilotHuge aph = new AutoPilotHuge(vnh);
            aph.selectXPath("/*/*[not(name() = name(preceding-sibling::*[1]))]");
            int i ;
            while ((i=aph.evalXPath())!=-1){
                System.out.println(" element name is "+vnh.toString(i));
            }
        }else System.out.println("Doc not mapped");
    }
}

but when I run it without result , so that's mean XML file it was not mapped in memory ... my question is how I can force mapping xml file in VTD-XML ?

役に立ちましたか?

解決

Put the follow code piece in and print out the exception to see what is wrong...

import java.io.IOException;

import com.ximpleware.extended.*;
public class testExtendedVTD {
    public static void main(String s[]){
        VTDGenHuge vgh = new VTDGenHuge();
        XMLBuffer xb = new XMLBuffer(); //or XMLMemeMappedBuffer
        try {
            xb.readFile("test.xml");
            vgh.setDoc(xb);
        } catch (ParseExceptionHuge e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        } catch (IOException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
    }
}
ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top