解决JDOM生成XML时半角空格被移除的问题
今天干活时发现的,老实说,我并不知道这个问题为什么产生。
因为我看到API是这样的:
PRESERVE (Default) All content is printed in the format it was created, no whitespace or line separators are are added or removed.
TRIM_FULL_WHITE Content between tags consisting of all whitespace is not printed. If the content contains even one non-whitespace character, it is all printed verbatim, whitespace and all.
TRIM All leading and trailing whitespace is trimmed.
NORMALIZE Leading and trailing whitespace is trimmed, and any ‘internal’ whitespace is compressed to a single space.
也就是说默认情况下,TextMode就是为PRESERVE
但是事实上,我的为TRIM_FULL_WHITE。
在生成XML前手动设定Format的TextMode为PRESERVE问题解决。
先标记这个问题。以后有时间再仔细看看。
public void saveXMLToOutputStream(OutputStream os) throws IOException {
Format format = Format.getCompactFormat();
XMLOutputter XMLOut;
if (outputAutoFormat) {
format.setEncoding(setEncoding);
format.setIndent(Constants.TSV_DEFAULT_SPLIT_CHARACTER);
format.setTextMode(TextMode.PRESERVE);
XMLOut = new XMLOutputter(format);
} else {
XMLOut = new XMLOutputter();
}
XMLOut.output(getXmlDoc(), os);
}