26 Feb 2004 21:16
Getting title tag text
Steve McCann <stevem <at> solveinteractive.com>
2004-02-26 20:16:43 GMT
2004-02-26 20:16:43 GMT
Using the following code, the assert for the title fails (getTitle()
returns an empty string). Is it not possible to retrieve that
information using the lexer rather than the parser? I am using HTML
Parser Integration Release 1.4-20040125.
Thank you,
Steve
public void testTitleScan() throws ParserException
{
String inputHTML =
"<html><!--remark--><head><title>Yahoo!</title></head>";
Lexer lexer = new Lexer (new Page (inputHTML));
PrototypicalNodeFactory factory =
new PrototypicalNodeFactory(new
TitleTag());
lexer.setNodeFactory (factory);
Node node;
while (null != (node = lexer.nextNode ()))
{
if (node instanceof TitleTag)
{
TitleTag titleTag = (TitleTag) node;
String test = titleTag.getTitle();
assertEquals("Title","Yahoo!",titleTag.getTitle());
}
(Continue reading)
RSS Feed