如何使用 Tika Sax ContentHandler 从基本标签获取 href 属性?
How to get href attribute from base tag using Tika Sax ContentHandler?
通过实施 org.xml.sax.helpers.DefaultHandler 并为 Tika 创建 ContentHandler,我可以解析 html 文件并通过覆盖 startElement 获取任何标签及其属性。总的来说,这非常有效(非常好的性能并且可以处理大文件)。但是,对于基本标签
<base href="http://www.w3schools.com/images/" target="_blank">
属性始终为空。其他标签的所有属性都可以正常工作。想知道为什么会这样吗?
@Override
public void startElement(String uri, String local, String name, Attributes attributes) {
if (XHTML.equals(uri)) {
if("base".equals(local)) {
String href = attributes.getValue("", "href"); // always null
System.out.println("base href: " + href);
}
}
}
由于 Tika 中的一个已知错误,无法从基本标签中获取属性 XHTMLContentHandler doesn't pass attributes of html element
通过实施 org.xml.sax.helpers.DefaultHandler 并为 Tika 创建 ContentHandler,我可以解析 html 文件并通过覆盖 startElement 获取任何标签及其属性。总的来说,这非常有效(非常好的性能并且可以处理大文件)。但是,对于基本标签
<base href="http://www.w3schools.com/images/" target="_blank">
属性始终为空。其他标签的所有属性都可以正常工作。想知道为什么会这样吗?
@Override
public void startElement(String uri, String local, String name, Attributes attributes) {
if (XHTML.equals(uri)) {
if("base".equals(local)) {
String href = attributes.getValue("", "href"); // always null
System.out.println("base href: " + href);
}
}
}
由于 Tika 中的一个已知错误,无法从基本标签中获取属性 XHTMLContentHandler doesn't pass attributes of html element