Untitled

mail@pastecode.io avatar
unknown
plain_text
24 days ago
1.7 kB
2
Indexable
Never
import com.ximpleware.AutoPilot;
import com.ximpleware.VTDGen;
import com.ximpleware.VTDNav;

public class VtdXmlParser {
    public static void main(String[] args) {
        try {
            // Đọc tệp XML
            VTDGen vg = new VTDGen();
            vg.parseFile("path/to/your/file.xml", true);

            VTDNav vn = vg.getNav();
            AutoPilot moduleAP = new AutoPilot(vn);
            AutoPilot tcAP = new AutoPilot(vn);
            AutoPilot testAP = new AutoPilot(vn);

            // Thiết lập XPath cho mỗi cấp độ
            String moduleXPath = "//module";
            String tcXPath = "//module/TC";
            String testXPath = "//module/TC/test";

            moduleAP.selectXPath(moduleXPath);
            tcAP.selectXPath(tcXPath);
            testAP.selectXPath(testXPath);

            // Thực hiện truy vấn XPath và in ra thông tin
            for (int moduleResult = -1; (moduleResult = moduleAP.evalXPath()) != -1; ) {
                for (int tcResult = -1; (tcResult = tcAP.evalXPath()) != -1; ) {
                    for (int testResult = -1; (testResult = testAP.evalXPath()) != -1; ) {
                        int moduleIndex = vn.getText();
                        int tcIndex = vn.getText(tcResult);
                        int testIndex = vn.getText(testResult);

                        System.out.println("Module TC Test: " +
                                vn.toNormalizedString(moduleIndex) + " " +
                                vn.toNormalizedString(tcIndex) + " " +
                                vn.toNormalizedString(testIndex));
                    }
                }
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}