相关代码;实例化 SAXSource
时的 barfs:
TransformerFactory factory = TransformerFactory.newInstance();
XMLReader xmlReader = XMLReaderFactory.createXMLReader("org.ccil.cowan.tagsoup.Parser");
Source input = new SAXSource(xmlReader, "http://books.toscrape.com/");
Result output = new StreamResult(System.out);
factory.newTransformer().transform(input, output);
JavaDoc 的 say :
public SAXSource(XMLReader reader,
InputSource inputSource)
Create a SAXSource, using an XMLReader and a SAX InputSource. The Transformer or SAXTransformerFactory will set itself to be the reader's ContentHandler, and then will call reader.parse(inputSource).
查看InputSource
显示:
InputSource(InputStream byteStream)
Create a new input source with a byte stream.
InputSource(Reader characterStream)
Create a new input source with a character stream.
因此,这需要 example ,要在 InputStream
的 html
中读取的字符流??
tagsoup
更好地用于 this身份转变?但是,怎么办?
最佳答案
有一个构造函数https://docs.oracle.com/javase/8/docs/api/org/xml/sax/InputSource.html#InputSource-java.lang.String-需要一个系统 ID,例如URL,以便您可以使用 Source input = new SAXSource(xmlReader, new InputSource("http://books.toscrape.com/"));
.
关于java - SAX错误: incompatible types: String cannot be converted to InputSource,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54041860/