【问题标题】:How to get href attribute from base tag using Tika Sax ContentHandler?如何使用 Tika Sax ContentHandler 从基本标签中获取 href 属性?
【发布时间】:2015-05-30 07:10:31
【问题描述】:

通过实现 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);
    }
  }
}

【问题讨论】:

    标签: sax apache-tika


    【解决方案1】:

    由于 Tika XHTMLContentHandler doesn't pass attributes of html element 中的一个已知错误,无法从基本标签中获取属性

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-01-09
      • 2011-05-21
      • 1970-01-01
      • 1970-01-01
      • 2016-04-22
      • 1970-01-01
      相关资源
      最近更新 更多