Java 如何解码字符串中编码的特殊 XML 字符?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/2241787/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-13 05:09:16  来源:igfitidea点击:

How to decode encoded special XML characters in a string?

java

提问by user256239

I was given a string like

我得到了一个像

example.com/test?region=us&lang=en&jurisdiction=us

How can I write the java code to decode the encoded characters like

我如何编写 java 代码来解码编码的字符,如

& 

in the string. Is there any existing class/method to decode them?

在字符串中。是否有任何现有的类/方法来解码它们?

Thanks.

谢谢。

采纳答案by BalusC

To unescape HTML/XML entities, use Apache Commons LangStringEscapeUtilsor homegrow one.

要取消转义 HTML/XML 实体,请使用Apache Commons LangStringEscapeUtilshomegrow one

回答by Jaime Hablutzel

StringEscapeUtilsseems to escape everything

StringEscapeUtils似乎逃避了一切

回答by Roger F. Gay

You can also include special characters in XPL. XPL has exactly the same structure as XML, but allows special characters. There is an XML parser with source code available for transformations at http://hll.nu

您还可以在 XPL 中包含特殊字符。XPL 具有与 XML 完全相同的结构,但允许使用特殊字符。在http://hll.nu 上有一个带有源代码的 XML 解析器可用于转换