gpt4 book ai didi

java - 将所有 xml 实体更改为 html

转载 作者:行者123 更新时间:2023-12-02 00:46:32 25 4
gpt4 key购买 nike

我正在阅读一个可能包含 XML 实体(如  )的文档。

由于我需要导出 txt 文件,因此我必须手动将实体从 XML 转换为文本。

如下所示。

reader = new BufferedReader(new InputStreamReader(is, "utf-8"));
while ((s = reader.readLine()) != null) {
if (s.equals("&#160"))
s= " ";
}

由于有很多 xml 实体,我想将它们全部转换为  ->space 之类的文本,并且更愿意避免 if then,是否有通用的方法来做到这一点?

最佳答案

当您从 中提取数字时,您可以执行以下操作:

(new String(new byte[]{(byte)160}, "ISO-8859-1")).

以下是实体映射:HTML ISO-8859-1 Reference

关于java - 将所有 xml 实体更改为 html,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4867964/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com