我以这种方式将 org.w3c.dom.Element 转换为 String:
StringWriter writer = new StringWriter();
Transformer transformer = TransformerFactory.newInstance().newTransformer();
transformer.setOutputProperty(OutputKeys.ENCODING, "UTF-8");
transformer.transform(new DOMSource(node), new StreamResult(writer));
String result = writer.toString();
但是当我稍后使用它时,我得到一个异常:io.MalformedByteSequenceException: Invalid byte 1 of 1-byte UTF-8 sequence表示错误编码。