0

I am using the following code to dynamically generate xml

def testXML(){

    render( contentType:"text/xml" ) {
        book() {
            author( name:'author')
        }
    }
}

The xml file is missing the xml header

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

The generated xml looks as follows:

enter image description here

How can i add the xml version and encoding header? Thanks for the help!

kofhearts
  • 3,607
  • 8
  • 46
  • 79
  • An XML declaration is not mandatory. Why do you need it? – wasmachien Aug 13 '20 at 06:17
  • is there a risk of leaving out the header? i guess for completeness sake. – kofhearts Aug 13 '20 at 06:21
  • No, as long as your file is UTF-8 encoded it should not be necessary. Maybe try checking the source of the web page, it could be that your browser does not display it. If it's really not there, try adding `;charset=utf-8` to your content type. – wasmachien Aug 13 '20 at 09:24
  • thanks! ill skip the header then. you can post your answer and i will accept it. thanks! – kofhearts Aug 14 '20 at 02:13

1 Answers1

1

As long as your file is UTF-8 encoded the declaration should not be necessary. Maybe try checking the source of the web page, it could be that your browser does not display it. If it's really not there, try adding ;charset=utf-8 to your content type.

wasmachien
  • 969
  • 1
  • 11
  • 28