1

This might be an repeat question, but now I have search all over the place and still not able to produce the output.

Currently I am getting the xml output, however I am not able to produce the encoding information.

I want this -> <?xml version=“1.0” encoding=“UTF-8”?> to be added in the 1st line of the xml output.

@RequestMapping(value = "/ergoproject",method = RequestMethod.GET, produces = MediaType.APPLICATION_XML_VALUE)

The above snippet is used for the xml output which is like this...

<List xmlns="">
    <item>
    <projectname>Test1</projectname>
    </item>
    <item>
    <projectname>Test2</projectname>
    </item>
    <item>
    <projectname>TEST3</projectname>
    </item>
    <item>
    <projectname>Test4</projectname>
    </item>
    <item>
    <projectname>Test5</projectname>
    </item>
</List>
2
  • 1
    Why do you want to add that? It's optional unless you want to set non-default values, and all the values you are setting are optional. (Well, that would be true if you were using the right kind of quote marks, as it is, it's just going to generate an error). Commented Apr 13, 2016 at 8:44
  • It is one of the requirements... no issue with the output but need that line... Still no luck.. any other pointers Commented Apr 13, 2016 at 9:41

1 Answer 1

1

Try to use:

Transformer t = TransformerFactory.newInstance().newTransformer();
t.setOutputProperty(OutputKeys.OMIT_XML_DECLARATION, "no");

See the docs:

omit-xml-declaration specifies whether the XSLT processor should output an XML declaration; the value must be yes or no.

Sign up to request clarification or add additional context in comments.

2 Comments

@jack:- Can you show how you are writing to your xml?
I am no expert with java, but XML output is from @requestmapping.. if I use ....MediaType.APPLICATION_JSON_VALUE, i get an json output. I am more interested in getting the 1st line in the xml output. Since there are some confidentiality issue, i cannot put the code part here. I am using java, intellij and springboot

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.