1
在JAVA中使用SAX解析器解析XML时,我无法像使用XML那样获取数据。 问题是如果节点包含一些unicode字符的文本数据。如何在不修剪两个Unicode字符之间的空格的情况下从XML节点获取文本
node.getTextContent()
正在将内容分解为unicode字符并修剪两个unicode字符之间的空格。
假设节点有数据oro-maxilo-facială și implantologie
。 请注意ă și
之间的空格。
方法node.getTextContent()
返回字符串为oro-maxilo-facialăși implantologie
(无空白)。
下面是我试过的代码。
private String getNodeContent(Element nodeToSerialize) {
StringBuffer sb = new StringBuffer();
if (nodeToSerialize.hasChildNodes()) {
NodeList nodeList = nodeToSerialize.getChildNodes();
for (int x = 0; x < nodeList.getLength(); x++) {
Node node = nodeList.item(x);
sb.append(node.getTextContent());
}
}
return sb.toString();
}
XML内容
<record>
<isbn>1234-5689</isbn>
<titles>
<title>Revista de chirurgie oro-maxilo-facială și implantologie</title>
</titles>
<number>16</number>
</record>
请张贴一些代码,以便我们可以看到您到目前为止所尝试的内容。 – 2012-02-02 08:37:17
我已修改帖子以包含代码。请看看 – RKrishna 2012-02-02 08:41:55
请认真阅读一些XML。 – 2012-02-02 08:58:18