Uso l'XML-API Java (6) per applicare una trasformazione xslt su un documento html dal Web. Questo documento è xhtml ben formato e quindi contiene una specifica DTD valida (<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
). Ora si verifica un problema: trasformazione Uppon il processore XSLT tenta di scaricare la DTD e il server w3 lo nega con un errore HTTP 503 (a causa di Bandwith Limitation da w3).Java, xml, XSLT: prevenzione convalida DTD
Come è possibile impedire al processore XSLT di scaricare il dtd? Non ho bisogno del mio documento di input convalidato.
Source è:
import javax.xml.transform.Source;
import javax.xml.transform.Transformer;
import javax.xml.transform.TransformerFactory;
import javax.xml.transform.stream.StreamResult;
import javax.xml.transform.stream.StreamSource;
-
String xslt = "<?xml version=\"1.0\"?>"+
"<xsl:stylesheet version=\"1.0\" xmlns:xsl=\"http://www.w3.org/1999/XSL/Transform\">"+
" <xsl:output method=\"text\" />"+
" <xsl:template match=\"//html/body//div[@id='bodyContent']/p[1]\"> "+
" <xsl:value-of select=\".\" />"+
" </xsl:template>"+
" <xsl:template match=\"text()\" />"+
"</xsl:stylesheet>";
try {
Source xmlSource = new StreamSource("http://de.wikipedia.org/wiki/Right_Livelihood_Award");
Source xsltSource = new StreamSource(new StringReader(xslt));
TransformerFactory ft = TransformerFactory.newInstance();
Transformer trans = ft.newTransformer(xsltSource);
trans.transform(xmlSource, new StreamResult(System.out));
}
catch (Exception e) {
e.printStackTrace();
}
ho letto le seguenti quesitons qui su SO, ma tutti usano un altro XML-Api:
Grazie!
Nel caso qualcuno abbia gli stessi problemi: questo porta nella giusta direzione (ecco perché ho accettato la risposta). Se non vuoi restituire il DTD, puoi anche restituirne uno vuoto. – theomega
Per favore correggi le maiuscole: 'XmlReader' dovrebbe essere 'XMLReader' – wau