我们尝试通过 JAVA API 将 ISO 编码的 xml 插入 MarkLogic,但收到此错误。 xml中包含特殊字符,例如:注册商标符号 -
®
Bad Request. Server Message: XDMP-DOCUTF8SEQ: Invalid UTF-8 escape sequence at line 14145 -- document is not UTF-8 encoded.
代码:
DatabaseClient client = DatabaseClientFactory.newClient(IP, PORT,
DATABASE_NAME, USERNAME, PWD, Authentication.DIGEST);
// acquire the content
InputStream xmlDocStream = XMLController.class.getClassLoader()
.getResourceAsStream("path to xml file");
// create a manager for XML documents
XMLDocumentManager xmlDocMgr = client.newXMLDocumentManager();
// create a handle on the content
InputStreamHandle xmlhandle = new InputStreamHandle(xmlDocStream);
// write the document content
xmlDocMgr.write("/" + filename, xmlhandle);
最佳答案
斯拉文:
解决方案是在读取资源时通过将输入流包装在 InputStreamReader 中来指定当前的 ISO 编码:
当 Java API 知道内容具有不同的编码但假定内容已经是 UTF-8 时,它会转换为 UTF-8。有关编码转换的更多详细信息,请参阅:
http://docs.marklogic.com/guide/java/document-operations#id_11208
希望有帮助,
关于java - 无法通过 JAVA API 将带有 iso 编码的 xml 写入 Marklogic,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30027838/