先来说说异常
当我使用dom4j来将String类型转换成Document 时
String 里面包含了“&”符号,结果异常就这样出来了
Nested exception: The entity name must immediately follow the '&' in the entity reference
此时,该如何解决呢?
解法:
通过将String 内容replace掉、即string.replace("&", "XXX");
但这个XXX该填成什么值 dom4j才会把他当成原始的“&”保存在xml中呢?
大家细瞧dom4j的文档就可知道String 和xml转换时 “&” 是被当成“&”值来传递的
所以这里 只要 通过string.replace("&", "&") 便可以成功的把“&”保存到xml中了!
更多推荐
Nested exception: The entity name must immediately follow the '&'
发布评论