gpt4 book ai didi

xml - Groovy 中的 UnEscape Xml

转载 作者:数据小太阳 更新时间:2023-10-29 02:48:28 27 4
gpt4 key购买 nike

我正在尝试在 Groovy 中取消转义 xml:

<student><age value="20"></age></student>

 <student><age value="20"></age></student>

但我找不到任何可以完成此任务的库。我尝试使用 groovy.json.StringEscapeUtils.unescapeJavaScript 但它没有帮助。

有一个库 groovy.xml.XmlUtilescapeXml 方法但没有 unescape 方法。

我的使用目的是在 Elasticsearch v1.3.2 中使用这个 groovy 脚本,其中包含 groovy-all-2.3.2.jar

有什么建议吗?

最佳答案

您可以为此使用 apache 中的 commons-lang。

// For Grails (2), add:
//
// compile 'org.apache.commons:commons-lang3:3.3'
//
// to your build config. For a groovy script, we can do:

@Grab('org.apache.commons:commons-lang3:3.3')
import org.apache.commons.lang3.StringEscapeUtils

def xml = '&lt;student&gt;&lt;age value=&quot;20&quot;&gt;&lt;/age&gt;&lt;/student&gt;'

def unescaped = StringEscapeUtils.unescapeXml(xml)

比自己编写和维护更容易 ;-)

关于xml - Groovy 中的 UnEscape Xml,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32097696/

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