GPathResult to String without XML declaration
问题 I'm converting GPathResult to String using def gPathResult = new XmlSlurper().parseText('<node/>') XmlUtil.serialize(gPathResult) It works fine, but I'm getting XML declaration in front of my XML <?xml version="1.0" encoding="UTF-8"?><node/> How can I convert GPathResult to String without <?xml version="1.0" encoding="UTF-8"?> at the beginning? 回答1: Use XmlParser instead of XmlSlurper : def root = new XmlParser().parseText('<node/>') new XmlNodePrinter().print(root) Using new XmlNodePrinter