首页 > 解决方案 > 当没有特殊字符可见时,为什么我不断收到字符“”是无效的 XML 字符

问题描述

我正在尝试对带有内容的 docx 文件进行语言环境翻译

Name
Name <emp/100>
AccProd < Tool>
Data <Cont:9000000>
ML <mail@gmail.com>
Alto <TL100>
Test<888>
Address < India>
Mode <AUTO>
Mode <manual>

但我没有得到正确的翻译文件,它一直给出这个错误(belo),但它没有说明它发现哪个字符无效。

org.w3c.dom.DOMException: STRING_TOO_LONG: 
The resulting string is too long to fit in a DOMString: 'The character ' ' is an invalid XML character'.
Caused by: java.io.IOException: The character ' ' is an invalid XML character

代码 :

DOMImplementationLS ls = (DOMImplementationLS) document.getImplementation();
LSSerializer ser = ls.createLSSerializer();
String xml = ser.writeToString(currentNode);  ------> this is where is throws exceptions

currentNode = 待翻译文档中的节点

标签: javadomw3c

解决方案


我发现问题是由于多个线程尝试访问文档并对其进行序列化,而另一个线程使用带有不完整 xml 数据的文档。在描述中保持提到的代码在同步块中工作正常,没有奇怪的异常。因为我是新手,所以它很有学习经验。感谢大家花时间审查我的问题。@VGR @hooknc @vanje


推荐阅读