当前位置: 技术问答>java相关
XML parsing and saving using xalan
来源: 互联网 发布时间:2015-06-30
本文导语: I have developped some java-xml applicaitons under jdk1.4. Now I would like to replace the XML parser with Xalan, however there is an error as below. Notice that the parsing works fine, but when I try to save the document into a file, the er...
I have developped some java-xml applicaitons under jdk1.4. Now I would like to replace the XML parser with Xalan, however there is an error as below. Notice that the parsing works fine, but when I try to save the document into a file, the error occur. And it work perfectly under jaxp reference implementation from sun. Any suggestions?
/*code*/
FileWriter out = new FileWriter(outputFile);
TransformerFactory tFactory = TransformerFactory.newInstance();
Transformer transformer = tFactory.newTransformer();
transformer.transform(new DOMSource(myDoc), new StreamResult(outputFile));
/*code*/
/*error*/
java.lang.NoSuchMethodError
at org.apache.xpath.DOM2Helper.getNamespaceOfNode(DOM2Helper.java:348)
at org.apache.xml.utils.TreeWalker.startNode(TreeWalker.java:368)
at org.apache.xml.utils.TreeWalker.traverse(TreeWalker.java:192)
at org.apache.xalan.transformer.TransformerIdentityImpl.transform(TransformerIdentityImpl.java:322)
at crmloyalty.ConfigParser.saveXMLFile(ConfigParser.java:215)
at crmloyalty.ConfigParser.setAllParameters(ConfigParser.java:201)
at crmloyalty.ModelForecastDataServlet.doPost(ModelForecastDataServlet.java:107)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:760)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:853)
at org.apache.tomcat.core.ServletWrapper.doService(ServletWrapper.java:405)
at org.apache.tomcat.core.Handler.service(Handler.java:287)
at org.apache.tomcat.core.ServletWrapper.service(ServletWrapper.java:372)
at org.apache.tomcat.core.ContextManager.internalService(ContextManager.java:812)
at org.apache.tomcat.core.ContextManager.service(ContextManager.java:758)
at org.apache.tomcat.service.http.HttpConnectionHandler.processConnection(HttpConnectionHandler.java:213)
at org.apache.tomcat.service.TcpWorkerThread.runIt(PoolTcpEndpoint.java:416)
at org.apache.tomcat.util.ThreadPool$ControlRunnable.run(ThreadPool.java:501)
at java.lang.Thread.run(Thread.java:484)
/*error*/
/*code*/
FileWriter out = new FileWriter(outputFile);
TransformerFactory tFactory = TransformerFactory.newInstance();
Transformer transformer = tFactory.newTransformer();
transformer.transform(new DOMSource(myDoc), new StreamResult(outputFile));
/*code*/
/*error*/
java.lang.NoSuchMethodError
at org.apache.xpath.DOM2Helper.getNamespaceOfNode(DOM2Helper.java:348)
at org.apache.xml.utils.TreeWalker.startNode(TreeWalker.java:368)
at org.apache.xml.utils.TreeWalker.traverse(TreeWalker.java:192)
at org.apache.xalan.transformer.TransformerIdentityImpl.transform(TransformerIdentityImpl.java:322)
at crmloyalty.ConfigParser.saveXMLFile(ConfigParser.java:215)
at crmloyalty.ConfigParser.setAllParameters(ConfigParser.java:201)
at crmloyalty.ModelForecastDataServlet.doPost(ModelForecastDataServlet.java:107)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:760)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:853)
at org.apache.tomcat.core.ServletWrapper.doService(ServletWrapper.java:405)
at org.apache.tomcat.core.Handler.service(Handler.java:287)
at org.apache.tomcat.core.ServletWrapper.service(ServletWrapper.java:372)
at org.apache.tomcat.core.ContextManager.internalService(ContextManager.java:812)
at org.apache.tomcat.core.ContextManager.service(ContextManager.java:758)
at org.apache.tomcat.service.http.HttpConnectionHandler.processConnection(HttpConnectionHandler.java:213)
at org.apache.tomcat.service.TcpWorkerThread.runIt(PoolTcpEndpoint.java:416)
at org.apache.tomcat.util.ThreadPool$ControlRunnable.run(ThreadPool.java:501)
at java.lang.Thread.run(Thread.java:484)
/*error*/
|
可他是Save Document,不可能构造StreamSource啊
|
You can try replacing DOMSource with StreamSource .