2013-03-01 294 views
1

我想使用XSLT轉換xml。我的xml在xml doctype中有「https」的dtd文件的url。如果我刪除這個文檔類型,我可以轉換文件,但與文檔類型我得到以下錯誤。javax.xml.transform.TransformerException:com.sun.org.apache.xml.internal.utils.WrappedRuntimeException:連接超時:連接

ERROR: 'Connection timed out: connect' 
ERROR: 'com.sun.org.apache.xml.internal.utils.WrappedRuntimeException: Connection timed out: connect' 
javax.xml.transform.TransformerException: javax.xml.transform.TransformerException: com.sun.org.apache.xml.internal.utils.WrappedRuntimeException: Connection timed out: connect 
    at com.sun.org.apache.xalan.internal.xsltc.trax.TransformerImpl.transform(TransformerImpl.java:719) 
    at com.sun.org.apache.xalan.internal.xsltc.trax.TransformerImpl.transform(TransformerImpl.java:313) 
    at Example.main(Example.java:59) 
Caused by: javax.xml.transform.TransformerException: com.sun.org.apache.xml.internal.utils.WrappedRuntimeException: Connection timed out: connect 
    at com.sun.org.apache.xalan.internal.xsltc.trax.TransformerImpl.getDOM(TransformerImpl.java:546) 
    at com.sun.org.apache.xalan.internal.xsltc.trax.TransformerImpl.transform(TransformerImpl.java:709) 
    ... 2 more 
Caused by: com.sun.org.apache.xml.internal.utils.WrappedRuntimeException: Connection timed out: connect 
    at com.sun.org.apache.xalan.internal.xsltc.dom.XSLTCDTMManager.getDTM(XSLTCDTMManager.java:446) 
    at com.sun.org.apache.xalan.internal.xsltc.dom.XSLTCDTMManager.getDTM(XSLTCDTMManager.java:234) 
    at com.sun.org.apache.xalan.internal.xsltc.trax.TransformerImpl.getDOM(TransformerImpl.java:524) 
    ... 3 more 
--------- 
javax.xml.transform.TransformerException: com.sun.org.apache.xml.internal.utils.WrappedRuntimeException: Connection timed out: connect 
    at com.sun.org.apache.xalan.internal.xsltc.trax.TransformerImpl.getDOM(TransformerImpl.java:546) 
    at com.sun.org.apache.xalan.internal.xsltc.trax.TransformerImpl.transform(TransformerImpl.java:709) 
    at com.sun.org.apache.xalan.internal.xsltc.trax.TransformerImpl.transform(TransformerImpl.java:313) 
    at Example.main(Example.java:59) 
Caused by: com.sun.org.apache.xml.internal.utils.WrappedRuntimeException: Connection timed out: connect 
    at com.sun.org.apache.xalan.internal.xsltc.dom.XSLTCDTMManager.getDTM(XSLTCDTMManager.java:446) 
    at com.sun.org.apache.xalan.internal.xsltc.dom.XSLTCDTMManager.getDTM(XSLTCDTMManager.java:234) 
    at com.sun.org.apache.xalan.internal.xsltc.trax.TransformerImpl.getDOM(TransformerImpl.java:524) 
    ... 3 more 
--------- 
com.sun.org.apache.xml.internal.utils.WrappedRuntimeException: Connection timed out: connect 
    at com.sun.org.apache.xalan.internal.xsltc.dom.XSLTCDTMManager.getDTM(XSLTCDTMManager.java:446) 
    at com.sun.org.apache.xalan.internal.xsltc.dom.XSLTCDTMManager.getDTM(XSLTCDTMManager.java:234) 
    at com.sun.org.apache.xalan.internal.xsltc.trax.TransformerImpl.getDOM(TransformerImpl.java:524) 
    at com.sun.org.apache.xalan.internal.xsltc.trax.TransformerImpl.transform(TransformerImpl.java:709) 
    at com.sun.org.apache.xalan.internal.xsltc.trax.TransformerImpl.transform(TransformerImpl.java:313) 
    at Example.main(Example.java:59) 
--------- 
java.net.ConnectException: Connection timed out: connect 
    at java.net.PlainSocketImpl.socketConnect(Native Method) 
    at java.net.PlainSocketImpl.doConnect(PlainSocketImpl.java:333) 
    at java.net.PlainSocketImpl.connectToAddress(PlainSocketImpl.java:195) 
    at java.net.PlainSocketImpl.connect(PlainSocketImpl.java:182) 

我無法刪除這種在實際場景中的文檔類型。請幫忙。

回答

2

您正在收到錯誤,因爲解析器正在Web上解析DOCTYPE中URL處的DTD。此提取失敗。

您需要在本地存儲DTD,並使用EntityResolver來使用本地副本。

看到這個問題和頂部的答案,看看如何做到這一點。 Prevent DTD download when using XSLT i.e. XML Transformer

+0

感謝@Alohci,它正在工作,但無論如何,我們可以忽略dtd下載和驗證?在我的活動場景中,我可以接收多種XML,並且無法在本地保留並跟蹤所有xml的dtd。 – 2013-03-04 14:46:05

+0

如果您在entityResolver與該URL匹配時返回空字符串,那麼實際上不會進行驗證,您也不必在本地保留DTD的副本。如果在DTD中定義了任何實體,顯然你會失去這些信息。 – Alohci 2013-03-04 15:35:18

+0

它的工作原理,感謝@Alohci的幫助 – 2013-03-06 06:22:29