Needs to delete complete node when child element meets condition and iterate further

User234
2014-06-10
2014-06-27
  • User234

    User234 - 2014-06-10

    Hi,
    I am tring to delete complete node based on value of child node, I am able to delete first node but the code throwing exception while removing next node.

    ap.declareXPathNameSpace("ns","http://ddd.dddddd.ec/CD333A");
    //ap.selectXPath("/ns:CD303A/IMPOPE200/*");
    ap.selectXPath("/ns:CD333A/IMPOPE200/ENSRisIMP902");
    int result = -1;
    int count = 0;
    XMLModifier xm = new XMLModifier(vn);;
    ArrayList <Long> ls = new ArrayList<Long>();
    while((result = ap.evalXPath())!=-1){
    System.out.print(""+result+" ");
    String key = vn.toString(result);
    System.out.print("Element name ==> "+key);
    int t = vn.getText(); // get the index of the text (char data or CDATA)
    NodeRecorder nr = new NodeRecorder(vn);

                if (t!=-1) {
    
                String val = vn.toNormalizedString(t);
                System.out.println(" Text  ==> "+val);              
                if (key != null && key.equals("ENSRisIMP902")
                        && val != null && !val.equals(null) && Integer.parseInt(val) == 0) {
                    VTDNav vn1 = (VTDNav)vn.duplicateNav();
                    vn1.toElement(VTDNav.P); // get to A node
                    long l = vn1.getElementFragment();//.getElementFragment();//.getContentFragment();
    
                    xm.remove(l);
                    //xm.bind(vn);
                    ls.add(l);
    
                   }
    
                }
                System.out.println("\n ============================== ");
                count++;
    
            }
    
            /*for (int i=0;i<ls.size();i++){
                long l = ls.get(i);
                xm.remove(l);
            }*/
    
            xm.output("C:\\WORKSPACE\\AlertMonitor\\output.xml");
            System.out.println("Total # of element "+count);
    

    I am getting below error; appreciate your help on to further progress

     
  • jimmy zhang

    jimmy zhang - 2014-06-27

    I believe this is a bug that may have been reported and fixed, can you download version 2.12 from cvs and do a compile and give another try?

     

Log in to post a comment.