java - SAX错误: incompatible types: String cannot be converted to InputSource

标签 java xml xslt saxon tag-soup

相关代码;实例化 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 ,要在 InputStreamhtml 中读取的字符流??

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/

相关文章:

java - Spring AOP 在 Tomcat 和 tcserver 中不起作用

java - 我的游戏需要数据库吗?

c# - 在类中使用数组进行 XML 反序列化

xml - 返回 XML 文件中的所有节点,即使它们为空

xml - 如何在 for-each xslt 语句中选择父节点的每个子节点?

c# - 使用 XPath/应用 XSL 转换遍历任意 C# 对象图

java - 是否可以在( native )调用过程中的对象上调用终结器?

java - 从 URI 检索 RDF 时如何设置 HTTP 超时?

xml - 使用 XSLT 转换 XSLT 时保留实体引用

java - 将对象写入java文件