Get nodes where child node contains an attribute

前端 未结 5 1168
长情又很酷
长情又很酷 2020-11-30 21:13

Suppose I have the following XML:


  Purgatorio
  Dante Alighieri<         


        
5条回答
  •  一生所求
    2020-11-30 21:22

    //book[title[@lang='it']]
    

    is actually equivalent to

     //book[title/@lang = 'it']
    

    I tried it using vtd-xml, both expressions spit out the same result... what xpath processing engine did you use? I guess it has conformance issue Below is the code

    import com.ximpleware.*;
    public class test1 {
      public static void main(String[] s) throws Exception{
          VTDGen vg = new VTDGen();
          if (vg.parseFile("c:/books.xml", true)){
              VTDNav vn = vg.getNav();
              AutoPilot ap = new AutoPilot(vn);
              ap.selectXPath("//book[title[@lang='it']]");
                      //ap.selectXPath("//book[title/@lang='it']");
    
              int i;
              while((i=ap.evalXPath())!=-1){
                  System.out.println("index ==>"+i);
              }
              /*if (vn.endsWith(i, "< test")){
                 System.out.println(" good ");  
              }else
                  System.out.println(" bad ");*/
    
          }
      }
    }
    

提交回复
热议问题