无法通过JAVA API将带有ISO编码的xml写入Marklogic

我们尝试通过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); 

Sravan:

解决方案是通过将输入流包装在InputStreamReader中来读取资源时指定当前的ISO编码:

http://docs.oracle.com/javase/8/docs/api/java/io/InputStreamReader.html#InputStreamReader-java.io.InputStream-java.lang.String-

当Java API知道内容具有不同的编码但是假设内容已经是UTF-8时,它将转换为UTF-8。 有关编码转换的更多详细信息,请参阅:

http://docs.marklogic.com/guide/java/document-operations#id_11208

希望有所帮助,