How to I output org.w3c.dom.Element to string format in java?

前端 未结 7 709
旧巷少年郎
旧巷少年郎 2020-11-27 13:01

I have an org.w3c.dom.Element object passed into my method. I need to see the whole xml string including its child nodes (the whole object graph). I am looking

7条回答
  •  生来不讨喜
    2020-11-27 13:48

    With VTD-XML, you can pass into the cursor and make a single getElementFragment call to retrieve the segment (as denoted by its offset and length)... Below is an example

    import com.ximpleware.*;
    public class concatTest{
        public static void main(String s1[]) throws Exception {
            VTDGen vg= new VTDGen();
            String s = "some  one";
            vg.setDoc(s.getBytes());
            vg.parse(false);
            VTDNav vn = vg.getNav();
            AutoPilot ap = new AutoPilot(vn);
            ap.selectXPath("/users/user/firstName");
            int i=ap.evalXPath();
            if (i!=1){
                long l= vn.getElementFragment();
                System.out.println(" the segment is "+ vn.toString((int)l,(int)(l>>32)));
            }
        }
    
    }
    

提交回复
热议问题