簡體   English   中英

通過HTTP輸出Java DOM

[英]Output Java DOM over HTTP

不久前,我找到了一種通過Servlet通過HTTP連接發送XML文檔的DOM表示的方法。 AFAIK為此需要DOM 3 LS(LoadStore),但是StackOverflow上顯示該操作方法的線程似乎已經消失了。

誰能告訴我該怎么做?

使用JAXP:

response.setHeader("Content-Type", "application/xml");
OutputStream out = response.getOutputStream();
TransformerFactory.newInstance().newTransformer().transform(new DOMSource(dom), new StreamResult(out));

您可能想改用JAX RS(從未使用過):

@Path("/foo.xml")
public class MyResource {
  @GET @Produces(MediaType.APPLICATION_XML)
  public Source asXml() {
     // TODO, get your DOM somehow
     return new DOMSource(dom);
  }
}

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM