我有一个由 UTF-16 编码的字符串。使用 解析时javax.xml.parsers.DocumentBuilder
,出现如下错误:
Character reference "�" is an invalid XML character
这是我用来解析 XML 的代码:
InputSource inputSource = new InputSource();
inputSource.setCharacterStream(new StringReader(xmlString));
DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
DocumentBuilder parser = factory.newDocumentBuilder();
org.w3c.dom.Document document = parser.parse(inputSource);
我的问题是,如何用(空格)替换无效字符?