【发布时间】:2012-06-22 18:18:57
【问题描述】:
我正在将 Web 服务中接收到的字符串转换为文档 (DOM) xml,如下所示:
Document file= null;
String xmlFile= "blablabla"; //latin1 encodeing
DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
DocumentBuilder builder = factory.newDocumentBuilder();
this.file = builder.parse(new InputSource(new StringReader(xmlFile)));
但是该字符串是用 ISO-8859-1 (latin1) 编码的,当我阅读本文档的一个节点时,我遇到了一些错误。如何使用 ISO-8859-1 编码正确创建 DOM 对象?或者如何读取字符串中编码为 Latin 1 的节点???
【问题讨论】:
-
xml的编码参数是什么?
-
-
Java 字符串始终为 UTF-16;真正的问题变成了“如何将 ISO-8859-1 数据读取到字符串中?” 说明您从中读取字符数据的数据源。
-
对了,字符串本身的数据是否正确?
-
我想是这样,但是信息是从控制台应用程序(使用 c#)发送到 Web 服务(使用 java)的协议就像这样 nameOfTheMethod(String xmlFile, int type)
标签: java string dom character-encoding iso-8859-1