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'。我正在把正确的绝对路径。 –