javax.xml.transform.TransformerException: XML-22103: (Fatal Error) DOMResult can

Caused by: javax.xml.transform.TransformerException: XML-22103: (Fatal Error) DOMResult can not be this kind of node.
	at oracle.xml.jaxp.JXTransformer.reportException(JXTransformer.java:917)
	at oracle.xml.jaxp.JXTransformer.transform(JXTransformer.java:371)
	at org.docx4j.org.xhtmlrenderer.resource.XMLResource$XMLResourceBuilder.createXMLResource(XMLResource.java:190)
	at org.docx4j.org.xhtmlrenderer.resource.XMLResource.load(XMLResource.java:75)
	at org.docx4j.convert.in.xhtml.XHTMLImporterImpl.convert(XHTMLImporterImpl.java:649)
	... 3 more

错误位置:

        for (Object p : paragraphs) {
             List<Object> texts = getAllElementFromObject(p, Text.class);
             for (Object t : texts) {
                 Text content = (Text) t;
              if (content.getValue().equals(placeholder)) {
                  toReplace = (P) p;
                  break;
              }
             }
        }
        XHTMLImporterImpl XHTMLImporter = new XHTMLImporterImpl(template);
        XHTMLImporter.setHyperlinkStyle("Hyperlink");
        try {
            toReplace.getContent().addAll(XHTMLImporter.convert(htmlToAdd, null) );
        } catch (Docx4JException e) {
            e.printStackTrace();
        } catch (JAXBException e) {
            e.printStackTrace();
        }
 

 

 

错误原因:寻找实现JAXP规范的XML解析器来解析XML文档,刚好xmlparserv2实现了JAXP规范,但它是用来解析Oracle XMLType类型的

 

 

修改方法:寻找另一个实现JAXP规范的XML解析器:xalan

xalan.jarxercesImpl.jarserializer.jar三个jar引入

在需要的地方强制调用

   System.setProperty("javax.xml.transform.TransformerFactory", "org.apache.xalan.processor.TransformerFactoryImpl");

    System.clearProperty("javax.xml.transform.TransformerFactory");

 

原文链接:加载失败,请重新获取