public String getWZdata(String id, String code, String xml) { System.out.println(id); System.out.println(code); //解析xml文件 SAXReader saxReader = new SAXReader(); Document document = null; try { document = saxReader.read(new ByteArrayInputStream(xml.getBytes("UTF-8"))); } catch (Exception e) { e.printStackTrace(); } Element element = document.getRootElement(); List<WZEntity> list = new ArrayList<>(); for (Iterator i = element.elementIterator("DATAINFO"); i.hasNext(); ) { Element root = (Element) i.next(); WZEntity wz = new WZEntity(); String key = UUID.randomUUID().toString().replaceAll("-", ""); //id wz.setId(key); //设置名称 wz.setName(root.elementText("DESC1")); //设置编码 wz.setCode(root.elementText("CODE")); //设置描述 wz.setDescription(""); //设置类别编码 wz.setCategorycode(root.elementText("")); //设置类别名称 wz.setCategoryname(root.elementText("DESC1")); //父类别编码(取得是父节点code) wz.setParentcode(root.elementText("PARENTCODE")); //版本号 wz.setSversion(root.elementText("VERSION")); //全局唯一编码 wz.setGuid(""); list.add(wz); } System.out.println(list.toString()+"aaaa"); //将接收到的数据插入数据库 // NewsDao n = new NewsDao(); // n.insert(list); StringBuilder sb = new StringBuilder(); // 得到当前节点属性name对象 Attribute attribute = element.attribute("SYSCODESYNCODE"); // 获得属性对象的值 String value1 = attribute.getValue(); // 得到当前节点属性name对象 Attribute attribute1 = element.attribute("UNIQUEID"); // 获得属性对象的值 String value2 = attribute1.getValue(); Attribute attribute2 = element.attribute("SYSCODE"); String value3 = attribute2.getValue(); sb.append("<DATAINFOS SYSCODESYNCODE=""); sb.append(value1); sb.append("" UNIQUEID=""); sb.append(value2); sb.append("" SYSCODE=""); sb.append(value3); sb.append("">"); for (Iterator i = element.elementIterator("DATAINFO"); i.hasNext(); ) { Element chiled1 = (Element) i.next(); sb.append(" <DATAINFO codeid="); sb.append("""); sb.append(chiled1.elementText("CODEID")); sb.append("""); sb.append(" version="); sb.append("""); sb.append(chiled1.elementText("VERSION")); sb.append(""");//得到版本号 sb.append(" status="0""); sb.append(" errorText="同步成功" "); sb.append("/>"); } sb.append(" </DATAINFOS>"); // System.out.println(sb.toString()+"bbbbb"); System.out.println("AAAA 插入数据成功"); return sb.toString(); }