Getting HTML title using HTMLEditorKit.ParserCallback

Discussion in 'Java' started by Bill Tschumy, Apr 22, 2004.

  1. Bill Tschumy

    Bill Tschumy Guest

    I am parsing an HTML file using ParseDelegator and a ParserCallback. I am
    trying to get the document title and the HREF links. The ParserCallback is
    successfully getting the HREF, so I know it is basically working. However,
    when I try to get the title, I always get back null. Here is the relevant
    code of the ParserCallback subclass. Anyone have any clue as to what I'm
    doing wrong?

    public void handleStartTag(HTML.Tag tag,
    MutableAttributeSet attrSet, int pos)
    {
    if (tag == HTML.Tag.TITLE)
    {
    urlTitle = (String)attrSet.getAttribute(HTML.Attribute.TITLE);
    System.out.println("attrSet: " + attrSet); // prints ""
    System.out.println("found title: " + urlTitle); // prints null
    }
    if (tag == HTML.Tag.A)
    {
    // This successfully gets the target URL
    String targetURLStr =
    (String)attrSet.getAttribute(HTML.Attribute.HREF);
    }

    }

    --
    Bill Tschumy
    Otherwise -- Austin, TX
    http://www.otherwise.com
     
    Bill Tschumy, Apr 22, 2004
    #1
    1. Advertising

  2. Bill Tschumy

    Guest

    Peace be unto you.

    It might work if the test case was
    <title title="Fun with markers">Crayon</title>

    "Unlike the TITLE element,
    which provides information
    about an entire document
    and may only appear once,
    the title attribute may
    annotate any number of elements.:"
    - http://www.w3.org/TR/html401/struct/global.html#h-7.4.2

    Have a good day.
     
    , Apr 22, 2004
    #2
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. plutian
    Replies:
    1
    Views:
    466
  2. Bruce Lee
    Replies:
    0
    Views:
    406
    Bruce Lee
    Dec 2, 2004
  3. tintac
    Replies:
    1
    Views:
    775
    Andrew Thompson
    Jan 29, 2005
  4. edi

    ParserCallback, position

    edi, Sep 10, 2005, in forum: Java
    Replies:
    1
    Views:
    400
    Dimitri Maziuk
    Sep 13, 2005
  5. k4
    Replies:
    1
    Views:
    507
    Tom Hawtin
    Apr 2, 2007
Loading...

Share This Page