我想获取xml内容然后更新它并将其发送回原来的位置,但是我的代码似乎已经添加了额外的字符(' \ r'和' \ n')使用此更新数据,因此它会增加文件大小,如何删除此字符? 当我第一次尝试更新我的xml时,它会更改xml标记值,但是在其他尝试中它既没有异常也没有更新数据,是因为这个' \ n'正在改变位置xml标签值? : 这是我的代码:
INSERT INTO translation(id_lang,key,translation,domain,theme)
VALUES (2,'Get our latest news and special sales','Rebeu les darreres notícies i ofertes','ShopThemeGlobal','classic');
例如xml数据如下所示:
def xml = new XmlParser().parseText(content)
for(int i=0;i<value.size();i++) {
date = value.get(i).substring(0, 10);
xml.Mr.ross.details.findAll( { p ->
p.runAs[0].text() == "true" && date.toString()== p.start[0].text();
}).each({ p ->
p.start[0].value =addDays( p.start[0].text())
p.runAs[0].value ="true"
})
}
def stringWriter = new StringWriter()
new XmlNodePrinter(new PrintWriter(stringWriter)).print(xml)
def newXml = stringWriter.toString()
String trimmedString = newXml.replaceAll("(?m)^[ \t]*\r?\n", "");
TransformerFactory transformerFactory = TransformerFactory.newInstance();
Transformer transformer = transformerFactory.newTransformer();
InputStream stream1 = new ByteArrayInputStream(trimmedString.getBytes("UTF-8"));
DocumentBuilderFactory dbFactory1 = DocumentBuilderFactory.newInstance();
dBuilder = dbFactory1.newDocumentBuilder();
document = dBuilder.parse(stream1);