【发布时间】:2020-06-16 19:34:03
【问题描述】:
我很难转义要由 Java 处理的 xml。我正在使用 JTidy 来转义不需要的字符,但很难从 <tag> capacity < 1000 </tag>
我正在使用下面的代码来转义输入
public String CleanXML(String input){
Tidy tidy = new Tidy();
tidy.setInputEncoding("UTF-16");
tidy.setOutputEncoding("UTF-16");
tidy.setWraplen(Integer.MAX_VALUE);
tidy.setXmlOut(true);
tidy.setSmartIndent(true);
tidy.setXmlTags(true);
tidy.setMakeClean(true);
tidy.setForceOutput(true);
tidy.setQuiet(true);
tidy.setShowWarnings(false);
StringReader in = new StringReader(input);
StringWriter out = new StringWriter();
tidy.parse(in, out);
return out.toString();
}
【问题讨论】:
-
<tag> capacity < 1000 </tag>的期望值是多少? -
Id 使用类似:
capacity esc( -
您从哪种输入开始?包含两个标签(如
<a>)和未转义尖括号(如size < 7)的字符串?这是相当肮脏的输入,看看它是如何创建的,并尝试创建一些更干净的东西,而不是事后收拾烂摊子。 -
我喜欢..,但问题是数据来自世界各地的技术人员平板电脑,这个选项有点不真实..