# Spring 輸出 XML [TOC] ###### tags: `spring` `xml` --- ## Web - 在 controller method 的 argument(s)裡帶入 `HttpServletResponse`。 - 該 controller method 的 return type 為 `void`,也就是不回傳。 ```java @GetMapping(path = "/proofOfConcept.xml", produces = MediaType.APPLICATION_XML_VALUE) void proofOfConcept(HttpServletResponse response) { Document document = DocumentBuilderFactory. newDefaultInstance(). newDocumentBuilder(). newDocument(); Element documentElement = document.createElement("document"); document.appendChild(documentElement); // DOM construction omitted for brevity TransformerFactory. newDefaultInstance(). newTransformer(). transform( new DOMSource( document ), new StreamResult( response.getOutputStream() ) ); } ```
×
Sign in
Email
Password
Forgot password
or
By clicking below, you agree to our
terms of service
.
Sign in via Facebook
Sign in via Twitter
Sign in via GitHub
Sign in via Dropbox
Sign in with Wallet
Wallet (
)
Connect another wallet
New to HackMD?
Sign up