word.xml加变量赋值后格式损坏(类似发表评论,脚本符号<>&)

时间:2022-11-09 19:26:43

如果传入的变量值包含脚本符号,会使格式错乱

  //格式化名称,防止xml出错
private String formatName(String name) {
name
= name.replace("&", "&amp;");
name
= name.replace(">", "&gt;");
name
= name.replace("<", "&lt;");
name
= name.replace("\"", "&quot;");
name
= name.replace("'", " &apos;");
return name;
}