我的项目中有一个奇怪的问题,比如我在webservice调用程序中收到错误
ERROR: 'DOM Level 3 Not implemented
在我的本地计算机上运行JAVA 1.6.0_45时。从我的项目中删除XALAN.jar。 在其中一个课程中我已经取代了
import org.apache.xml.utils.QName;
用
import javax.xml.namespace.QName; //its from jaxrpc.jar
尝试应用转换时出现错误
TransformerFactory xf = TransformerFactory.newInstance();
try {
Document responseDocument = (Document) object.newDomNode(options);
Transformer xformer = xf.newTransformer();
xformer.setOutputProperty(OutputKeys.METHOD, "xml");
xformer.setOutputProperty(OutputKeys.INDENT, "yes");
xformer.setOutputProperty(OutputKeys.ENCODING, "UTF-8");
StringWriter writer = new StringWriter();
Result out = new StreamResult(writer);
if (!xmlEscape) {
ProcessingInstruction pi = responseDocument
.createProcessingInstruction(
Result.PI_DISABLE_OUTPUT_ESCAPING, "");
responseDocument
.getDocumentElement()
.getParentNode()
.insertBefore(pi, responseDocument.getDocumentElement());
}
xformer.transform(new DOMSource(responseDocument), out);
// remove the <![CDATA[ before returning the response
return removeCdata(writer.getBuffer().toString());
} catch (TransformerConfigurationException e) {
throw new XMLSchemaException(
"Unable to generate request message due to " + e);
} catch (IllegalArgumentException e) {
throw new XMLSchemaException(
"Unable to generate request message due to " + e);
} catch (TransformerException e) {
throw new XMLSchemaException(
"Unable to generate request message due to " + e);
}
错误发生在行
中xformer.transform(new DOMSource(responseDocument), out);
任何帮助都将不胜感激。
编辑:此错误的主要原因是
TransformerFactory xf = TransformerFactory.newInstance();
返回weblogic.xml.jaxp.RegistrySAXTransformerFactory@16849e2a
而不是
com.sun.org.apache.xalan.internal.xsltc.trax.TransformerFactoryImpl
作为JAVA 6中的transformerfactory的默认实例。
答案 0 :(得分:0)
是否有一个临时修补程序通过将其转换为DOM3 compilant来解决此问题。而实际的解决方案是停止使用xecers,xbean。
Document responseDocument = (Document) object.newDomNode(options);
DocumentBuilder builder = DocumentBuilderFactory.newInstance()
.newDocumentBuilder();
Document doc3 = builder.newDocument();
Element newRoot = (Element) doc3.importNode(
responseDocument.getDocumentElement(), true);
doc3.appendChild(newRoot);
和传递新doc3的转换方法
xformer.transform(new DOMSource(doc3), out);