gpt4 book ai didi

java - 如何保存和编码带有特殊字符的xml字符串?

转载 作者:行者123 更新时间:2023-12-02 07:25:31 24 4
gpt4 key购买 nike

我有一个包含 xml 内容的字符串。当我将其保存到 File 时,结果包含诸如 < 之类的标签。 ” >

如何正确保存这样的字符串以便使用编码字符?

最佳答案

如果您决心打破 XML 规范,那么请使用...

http://commons.apache.org/lang/api-2.6/org/apache/commons/lang/StringEscapeUtils.html

方法“unes​​capeHtml”将满足您的要求。

Unescapes a string containing entity escapes to a string containing the actual Unicode characters corresponding to the escapes. Supports HTML 4.0 entities.

For example, the string "&lt;Fran&ccedil;ais&gt;" will become "<Français>"

If an entity is unrecognized, it is left alone, and inserted verbatim into the result string. e.g. "&gt;&zzzz;x" will become ">&zzzz;x".

关于java - 如何保存和编码带有特殊字符的xml字符串?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13629400/

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