how to get the attribute value of an xml node using java

前端 未结 6 826
抹茶落季
抹茶落季 2020-12-03 13:59

I\'ve an xml which looks like this:

{ .....         


        
6条回答
  •  天命终不由人
    2020-12-03 14:35

    Below is the code to do it in VTD-XML

    import com.ximpleware.*;
    
    public class queryAttr{
         public static void main(String[] s) throws VTDException{
             VTDGen vg= new VTDGen();
             if (!vg.parseFile("input.xml", false))
                return false;
             VTDNav vn = vg.getNav();
             AutoPilot ap = new AutoPilot(vn);
             ap.selectXPath("//xml/ep/source/@type");
             int i=0;
             while((i = ap.evalXPath())!=-1){
                   system.out.println(" attr val ===>"+ vn.toString(i+1));
    
             }
         }
    }
    

提交回复
热议问题