TransformerFactory and Xalan Dependency Conflict

后端 未结 6 1736
我寻月下人不归
我寻月下人不归 2021-01-12 21:54

I have the following code:

javax.xml.transform.TransformerFactory factory = TransformerFactory.newInstance();
factory.setAttribute(XMLConstants.ACCESS_EXTERN         


        
6条回答
  •  感情败类
    2021-01-12 22:41

    If you are multiple XSL processors and or different versions, you have to handle the case that not every implementation will be able to handle every attribute. The only way to do so is to catch the IllegalArgumentException that is thrown if the attribute is not supported. Take a look at this modified example from the JAXP documentation:

    javax.xml.transform.TransformerFactory factory = TransformerFactory.newInstance();
    
    try {
        factory.setAttribute(XMLConstants.ACCESS_EXTERNAL_DTD, "");
    } catch (IllegalArgumentException e) {
        //jaxp 1.5 feature not supported
    }
    

    The documentation says:

    When code change is possible, and for new development, it is recommended that the new properties be set as demonstrated above. By setting the properties this way, applications can be sure to maintain the desired behavior whether they are deployed to older or newer version of the JDK, or whether the properties are set through System Properties or jaxp.properties.

提交回复
热议问题