GPathResult转换为不带XML声明的字符串 [英] GPathResult to String without XML declaration
本文介绍了GPathResult转换为不带XML声明的字符串的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在使用
def gPathResult = new XmlSlurper().parseText('<node/>')
XmlUtil.serialize(gPathResult)
它工作正常,但是我在XML前面得到了XML声明
It works fine, but I'm getting XML declaration in front of my XML
<?xml version="1.0" encoding="UTF-8"?><node/>
如何在没有<?xml version ="1.0" encoding ="UTF-8"的情况下将
>一开始? GPathResult
转换为 String
?
How can I convert GPathResult
to String
without <?xml version="1.0" encoding="UTF-8"?>
at the beginning?
推荐答案
使用 XmlParser
代替 XmlSlurper
:
def root = new XmlParser().parseText('<node/>')
new XmlNodePrinter().print(root)
使用 new XmlNodePrinter(preserveWhitespace:true)
可能也是您尝试做的事情的朋友.请参阅文档中的其余选项: http://docs.groovy-lang.org/latest/html/gapi/groovy/util/XmlNodePrinter.html .
Using new XmlNodePrinter(preserveWhitespace: true)
may be your friend for what you're trying to do also. See the rest of the options in the docs: http://docs.groovy-lang.org/latest/html/gapi/groovy/util/XmlNodePrinter.html.
这篇关于GPathResult转换为不带XML声明的字符串的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文