简体   繁体   English

(SAXON DTD)java.net.SocketException:来自服务器的文件意外结束

[英](saxon dtd)java.net.SocketException: Unexpected end of file fromserver

I use Saxon(Java) to convert *.xhtml to *.xml . 我使用Saxon(Java)将*.xhtml转换为*.xml

Here is my java code: 这是我的Java代码:

System.setProperty("javax.xml.transform.TransformerFactory","net.sf.saxon.TransformerFactoryImpl");
TransformerFactory tfactory = TransformerFactory.newInstance();
System.out.println("load xslt file");
Templates templates = tfactory.newTemplates(new StreamSource(xsltFile));

Transformer transformer = templates.newTransformer();
Result result = new StreamResult(new File(filtTempXml));
transformer.transform(new StreamSource(xmlFile), result);

Because there is DTD in the *.xhtml file, like: 因为*.xhtml文件中包含DTD,例如:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" 
 "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">

The error: 错误:

 java.net.SocketException: Unexpected end of file from server

I want to know: 我想知道:

1) How to simply disable the dtd? 1)如何简单地禁用DTD?

2) If not, how to set catalog file(mapping dtd to local) for saxon in Java program? 2)如果没有,如何在Java程序中为saxon设置目录文件(将dtd映射到本地)? Any example? 有什么例子吗?

Thanks. 谢谢。

Finally, I know how to implement it. 最后,我知道如何实现它。

SAXParserFactory parserFactory = SAXParserFactory.newInstance();
SAXParser saxParser = parserFactory.newSAXParser();
XMLReader xmlReader = saxParser.getXMLReader();

EntityResolver entityReolver = new EntityResolver() {
    public InputSource resolveEntity(String publicId, String systemId) {
    try {
        System.out.println("Entity resolving systemID... " + publicId);
        if (systemId.indexOf((".dtd")) != -1) {
            System.out.println("Entity Resolved...");
            return new InputSource(new ByteArrayInputStream("<?xml version='1.0' encoding='UTF-8'?>".getBytes()));
        }
    } catch (Exception e) {
    }
    return null;
    }
};
xmlReader.setEntityResolver(entityReolver);

SAXSource saxSource = new SAXSource(xmlReader, SAXSource.sourceToInputSource(new   StreamSource(xmlFile)));
transformer.transform(saxSource, result);

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 引起:java.net.SocketException:来自服务器的文件意外结束 - Caused by: java.net.SocketException: Unexpected end of file from server 异常:java.net.SocketException:来自服务器的文件意外结束 - Exception: java.net.SocketException: Unexpected end of file from server java.net.SocketException:来自服务器的文件意外结束 - java.net.SocketException: Unexpected end of file from server 撒克逊人抛出 java.net.SocketException: - Saxon throwing java.net.SocketException: Java简单代码:java.net.SocketException:来自服务器的文件意外结束 - Java simple code: java.net.SocketException: Unexpected end of file from server HttpUrlConnection getOutputStream()抛出java.net.SocketException:服务器上的文件意外结束 - HttpUrlConnection getOutputStream() throwing java.net.SocketException: Unexpected end of file from server Solr SimplePostTool:读取响应时出现IOException:java.net.SocketException:服务器中的文件意外结束 - Solr SimplePostTool: IOException while reading response: java.net.SocketException: Unexpected end of file from server java.net.SocketException:服务器中的文件意外结束[但是此消息仅与一个特定的用户登录一起出现 - java.net.SocketException:Unexpected end of file from the server [but this message comes only with one particular user login javax.ws.rs.ProcessingException:java.net.SocketException:服务器中的文件意外结束 - javax.ws.rs.ProcessingException : java.net.SocketException: Unexpected end of file from server URLConnection无法发送完整的URL(java.net.SocketException:服务器上的文件意外结束) - URLConnection does not send full URL (java.net.SocketException: Unexpected end of file from server)
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM