2014-11-14 83 views

回答

0

我發現這個解決方案:

DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance(); 
// stop the network loading of DTD files 
factory.setValidating(false); 
factory.setNamespaceAware(true); 
factory.setFeature("http://xml.org/sax/features/namespaces", false); 
factory.setFeature("http://xml.org/sax/features/validation", false); 
factory.setFeature("http://apache.org/xml/features/nonvalidating/load-dtd-grammar", false); 
factory.setFeature("http://apache.org/xml/features/nonvalidating/load-external-dtd", false); 

(見這裏TransformerFactory - avoiding network lookups to verify DTDs

因爲我們知道<int-xml:xslt-transformer>支持source-factoryresult-factory,將有隻需要爲他們提供你的onw實現,例如根據現有的DomSourceFactoryDomResultFactory,分別在構造函數中注入那些代碼。

當然你可以注入DocumentBuilderFactoryDomSourceFactoryDomResultFactory,但你應該寫一些自定義的FactoryBean<DocumentBuilderFactory>在其getObject()初始化DocumentBuilderFactory