public static File updateXmlFile(String oldPath){ try{ File fileListXml = new File(oldPath); org.jsoup.nodes.Document xmlDocument= Jsoup.parse(fileListXml,"utf-8"); org.jsoup.nodes.Elements Elements=xmlDocument.getElementsByTag("修改的标签"); for (Element element:Elements) { element.text(修改成的值); } Element body = xmlDocument.body(); System.out.println(body.toString()); String s = body.toString(); String substring = s.substring(s.indexOf("<body>") +6, s.lastIndexOf("</body>") - 1); System.out.println(substring); org.dom4j.Document doc = DocumentHelper.parseText(substring); XMLWriter writer = new XMLWriter(new FileOutputStream(oldPath+"_01.xml")); // 设置是否转义,默认使用转义字符 writer.setEscapeText(false); writer.write(doc); writer.close(); }catch (Exception e){ e.printStackTrace(); } File file=new File(oldPath+"_01.xml"); return file; }
替换xml中值并生成本地文件
最新推荐文章于 2024-07-10 06:14:25 发布