VTD实现XML报文重写。
@Test public void testOverWrite() throws Exception{ VTDGen vg = new VTDGen(); vg.setDoc("<root><item>1</item><item>2</item><item>3</item><item>4</item></root>".getBytes()); HashMap m = new HashMap(); m.put("1","A"); m.put("2","B"); m.put("3","C"); m.put("4","D"); vg.parse(true); VTDNav vn = vg.getNav(); AutoPilot ap = new AutoPilot(vn); XMLModifier xm = new XMLModifier(vn); ap.selectXPath("//item"); while(ap.evalXPath() > -1){ System.out.println(vn.toString(vn.getText())); xm.updateToken(vn.getText(),(String)m.get(vn.toString(vn.getText()))); } ByteArrayOutputStream os = new ByteArrayOutputStream(); xm.output(os); System.out.println(os.toString()); os.flush(); os.close(); }原文链接:https://www.f2er.com/xml/300536.html