2010-03-23 52 views
5

Trong đoạn mã sau:java.io.IOException: Máy chủ trả lại mã phản hồi HTTP: 503 cho URL: http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd

private Document transformDoc(Source source) throws TransformerException, IOException { 
    TransformerFactory factory = TransformerFactory.newInstance(); 

    Transformer transformer = 
      factory.newTransformer(new StreamSource(xsltResource.getInputStream())); 
    JDOMResult result = new JDOMResult(); 
    transformer.transform(source, result); 
    return result.getDocument(); 
} 

tôi nhận được ngoại lệ này:

java.io.IOException: Server returned HTTP response code: 503 for URL: http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd 

các XHTML tôi dịch qua qua xsl là:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> 
<html xmlns="http://www.w3.org/1999/xhtml"> 
<head> 
    <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"/> 
    <title>Terms and Conditions</title> 
</head> 
<body> 
    <div>Test Content</div> 
</body> 
</html> 

làm thế nào để ngăn chặn sự biến Xalan từ điện thoại cho hom e?

Trả lời

1

This post from the Xalan-J mailing list đề xuất rằng "đúng cách" là để bạn tự định cấu hình chính mình Source/Reader của mình để tắt xác thực.

+0

Bạn cần những điều sau đây để có được nó đúng 100%, nhưng điều đó liên kết mailing list là hữu ích nhất! SAXParserFactory spf = SAXParserFactory.newInstance(); spf.setNamespaceAware (true); spf.setValidating (false); // Tắt xác thực spf.setFeature ("http://apache.org/xml/features/nonvalidating/load-external-dtd", sai); XMLReader rdr = spf.newSAXParser(). GetXMLReader(); –

2

Hoặc tắt DTD giải quyết trong trình phân tích cú pháp (trình phân tích cú pháp cụ thể) hoặc đặt trình phân giải đối tượng trống.

sao chép từ http://www.jdom.org/docs/faq.html#a0350:

public class NoOpEntityResolver implements EntityResolver { 
    public InputSource resolveEntity(String publicId, String systemId) { 
    return new InputSource(new StringBufferInputStream("")); 
    } 
} 

// Then in the builder... 

builder.setEntityResolver(new NoOpEntityResolver()); 
Các vấn đề liên quan