2
有沒有辦法通過REST服務將xsl和xsd應用於xml輸出?我使用JAXB 2.2 jre實現的Jersey 1.4。謝謝。不能使用MOXy或其他JaxB實現。謝謝。將XSLT和XSD Schema應用於通過Jersey Rest的xml輸出
有沒有辦法通過REST服務將xsl和xsd應用於xml輸出?我使用JAXB 2.2 jre實現的Jersey 1.4。謝謝。不能使用MOXy或其他JaxB實現。謝謝。將XSLT和XSD Schema應用於通過Jersey Rest的xml輸出
您可以從JAX-RS服務返回javax.ws.rs.core.StreamingOutput
。在您實現StreamingOutput
時,您可以將JAXB與XSLT和XSD配合使用。
public class MyStreamingOutput implements StreamingOutput {
private JAXBContext jc;
private Transformer t;
private XmlSchema s;
private Object o;
public MyStreamingOutput(JAXBContext jc, Transformer t, XmlSchema s, Object o) {
this.jc = jc;
this.t = t;
this.s = s;
this.o = o;
}
public void write(java.io.OutputStream output) throws java.io.IOException, WebApplicationException
Marshaller m = jc.createMarshaller();
m.setSchema(s);
JAXBSource source = new JAXBSource(m,o):
StreamResult result = new StreamResult(output);
t.transform(source, result);
}
}
它似乎工作,但是當我嘗試指定源作爲新的流源時,即使我指定文件的絕對路徑,我也會收到systemID錯誤。不知道什麼是錯的。 –
你的意思是'StreamResult'?是的,你可能需要做setSystemId(String)。奇怪你仍然看到一個例外。 –
'分配't'時'TransformerFactory.newInstance()。newTransformer(新的StreamsSource(String SystemId))''。那就是我得到未知的'SystemId'。我正在把正確的絕對路徑。 –