Xalan的XSLTC.compile可将XSL编译为class,本意上是为了提高效率;
可我看了它的调用与实现,好象只支持物理存储的XML。调用时必须DOMImpl dom = new DOMImpl()或从cache中retrieve,好丑陋的接口!
我的XML一般来源于内存字符串,如果来一次磁盘IO,然后再用Class.forName,理论上效率更低。
请问哪位使用过Xalan的这个功能,效率如何?有变通的方法可绕开磁盘IO吗?先谢谢了
...全文
8816打赏收藏
有谁用Xalan编译过XSL吗?
Xalan的XSLTC.compile可将XSL编译为class,本意上是为了提高效率; 可我看了它的调用与实现,好象只支持物理存储的XML。调用时必须DOMImpl dom = new DOMImpl()或从cache中retrieve,好丑陋的接口! 我的XML一般来源于内存字符串,如果来一次磁盘IO,然后再用Class.forName,理论上效率更低。 请问哪位使用过Xalan的这个功能,效率如何?有变通的方法可绕开磁盘IO吗?先谢谢了
看了第二遍,明白你意思了。
你所说的org.apache.xalan.xsltc.compiler.XSLTC
有很多种形式,你随便挑种就可以了,谁说只能从物理文件读取Document的?apache不会作出那么傻得类的。
boolean compile(InputSource input, java.lang.String name)
Compiles an XSL stylesheet passed in through an InputStream
boolean compile(java.io.InputStream stream, java.lang.String name)
Compiles an XSL stylesheet passed in through an InputStream
byte[][] compile(java.lang.String name, InputSource input)
Compiles a stylesheet pointed to by a URL.
byte[][] compile(java.lang.String name, InputSource input, int outputType)
Compiles a stylesheet pointed to by a URL.
boolean compile(java.net.URL url)
Compiles an XSL stylesheet pointed to by a URL
boolean compile(java.net.URL url, java.lang.String name)
Compiles an XSL stylesheet pointed to by a URL
boolean compile(java.util.Vector stylesheets)
Compiles a set of stylesheets pointed to by a Vector of URLs
==========================
就拿这条把
compile
public boolean compile(java.io.InputStream stream,
java.lang.String name)Compiles an XSL stylesheet passed in through an InputStream
Parameters:
input - An InputStream that will pass in the stylesheet contents
name - The name of the translet class to generate
Returns:
'true' if the compilation was successful
我想InputStream不必是一定是物理文件吧。
上面的文件再改一下!
public static void transformAndCompile(String stylesheet,String url,String className)
throws JDOMException {
try {
SAXBuilder builder = new SAXBuilder();
Document in = builder.build(url);
Transformer transformer = TransformerFactory.newInstance()
.newTransformer(new StreamSource(stylesheet));
JDOMResult out = new JDOMResult();
transformer.transform(new JDOMSource(in), out);
Document trasformed = out.getDeocument();
XMLOutputter xmlOutputter = new XMLOutputter();
// Output to the I/O stream
InputStream resultIn = new InputStream();
OutputStream resultOut = new OutputStream(resultIn);
xmlOutputter.output(trasformed , sourceOut);
org.apache.xalan.xsltc.compiler.XSLTC xsltc = new org.apache.xalan.xsltc.compiler.XSLTC ();
xsltc.compile(resultIn,className);
}
catch (TransformerException e) {
throw new JDOMException("XSLT Trandformation failed", e);
}
catch(XXXExeption...){..}
}