加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

没有XML声明的GPathResult到String

发布时间:2020-12-15 23:55:22 所属栏目:百科 来源:网络整理
导读:我正在使用GPathResult转换为String def gPathResult = new XmlSlurper().parseText('node/')XmlUtil.serialize(gPathResult) 它工作正常,但我在XML前面得到XML声明 ?xml version="1.0" encoding="UTF-8"?node/ 如何在没有?xml version =“1.0”encoding =
我正在使用GPathResult转换为String
def gPathResult = new XmlSlurper().parseText('<node/>')
XmlUtil.serialize(gPathResult)

它工作正常,但我在XML前面得到XML声明

<?xml version="1.0" encoding="UTF-8"?><node/>

如何在没有<?xml version =“1.0”encoding =“UTF-8”的情况下将GPathResult转换为String?>一开始?

使用XmlParser而不是XmlSlurper:
def root = new XmlParser().parseText('<node/>')
new XmlNodePrinter().print(root)

使用新的XmlNodePrinter(preserveWhitespace:true)可能是您尝试做的事情的朋友.请参阅文档中的其余选项:http://docs.groovy-lang.org/latest/html/gapi/groovy/util/XmlNodePrinter.html.

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读