Transformer我使用类和转换方法修改 XML 文件。它正确地修改了我的参数但改变了 XML 样式(以不同的方式编写 XML 属性):原来的:<a struct="b"></a><c></c>编辑后:<a struct="b"/><c/>我知道我可以设置属性:transformer.setOutputProperty(OutputKeys.KEY,value),但我没有找到合适的设置。谁能帮助变压器不改变写入格式?XMLReader xr = new XMLFilterImpl(XMLReaderFactory.createXMLReader()Source src = new SAXSource(xr, new InputSource(new StringReader(xmlArray[i])));<<modify xml>>TransformerFactory transFactory = TransformerFactory.newInstance();Transformer transformer = transFactory.newTransformer(); transformer.setOutputProperty(OutputKeys.OMIT_XML_DECLARATION,"yes"); StringWriter buffer = new StringWriter(); transformer.transform(src, new StreamResult(buffer)); xmlArray[i] = buffer.toString();
添加回答
举报
0/150
提交
取消