public static void main(String[] args) { String xmlStr = "<ybjcVo>"+ "<zbGrid>" + " <zbGridlbVO>" + " <ewblxh>1</ewblxh>" + " <lmc>本月数</lmc>" + " <yshwxse>按适用税率计算应税货物销售额</yshwxse>" + " <yslwxse>按适用税率计算应税劳务销售额</yslwxse>" + " <jxse>进项税额</jxse>" + " </zbGridlbVO>" + " <zbGridlbVO>" + " <ewblxh>3</ewblxh>" + " <lmc>本月数</lmc>" + " <yshwxse>按适用税率计算应税货物销售额</yshwxse>" + " <yslwxse>按适用税率计算应税劳务销售额</yslwxse>" + " <jxse>进项税额</jxse>" + " </zbGridlbVO>" + "</zbGrid>"+ "</ybjcVo>"; try { Document document = DocumentHelper.parseText(xmlStr); Document documentCreate = DocumentHelper.createDocument(); Element ybjcVoCreate = documentCreate.addElement("ybjcVo"); Element zbGridCreate = ybjcVoCreate.addElement("zbGrid"); Element ybjcVo = document.getRootElement(); Element zbGrid = ybjcVo.element("zbGrid"); Iterator<Element> zbGridlbVOList = zbGrid.elementIterator("zbGridlbVO"); while(zbGridlbVOList.hasNext()){ Element e = zbGridlbVOList.next(); String ewblxh = e.element("ewblxh").getText(); String lmc = e.element("lmc").getText(); String yshwxse = e.element("yshwxse").getText(); String yslwxse = e.element("yslwxse").getText(); String jxse = e.element("jxse").getText(); Element zbGridlbVOCreate = zbGridCreate.addElement("zbGridlbVO"); zbGridlbVOCreate.addAttribute("ewblxh", ewblxh); zbGridlbVOCreate.addAttribute("lmc", lmc); zbGridlbVOCreate.addAttribute("yshwxse", yshwxse); zbGridlbVOCreate.addAttribute("yslwxse", yslwxse); zbGridlbVOCreate.addAttribute("jxse", jxse); } String resultXml = documentCreate.asXML(); System.out.println("resultXml: "+resultXml); } catch (DocumentException ex) { Logger.getLogger(T02.class.getName()).log(Level.SEVERE, null, ex); } }