|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object com.cleancode.net.SimpleHtmlParse
public class SimpleHtmlParse
Extracts selected constructs from the structure of an HTML document.
Each piece is returned as a name/value pair through
a SimpleHtmlParse.Callback
object.
The caller may then do whatever is needed to the element.
These items are extracted from the document header:
title
elements)
meta
elements
link
elements)
a
elements)
These input elements fall into three categories, which determine the
resulting output.
The general form is (category:name, value)
.
The name may sometimes be blank, in which case
the preceding colon is omitted.
<TITLE>value</TITLE>
returned as (Title, value)
<!DOCTYPE HTML PUBLIC value
"http://www.w3.org/TR/REC-html40/loose.dtd">
returned as (DTD, value)
<META name=name content=value>
returned as (Meta:name, value)
<LINK rel=name href=value>
returned as (Include:name, value)
<A href=value>text</A>
returned as (Link:text, value)
<A href=value><img src="filename"></A>
returned as (Link:[#filename#], value)
Sample Usage:
SimpleHtmlParse parse = new SimpleHtmlParse( new SimpleHtmlParse.Callback() { public void addHtmlElement(String paramName, String paramValue) { System.out.println("NAME: "+paramName+", VALUE: "+paramValue); } }); parse.collectElements(content);
Nested Class Summary | |
---|---|
static interface |
SimpleHtmlParse.Callback
This interface provides a callback for the user to handle each parsed element. |
static class |
SimpleHtmlParse.Test
A standalone test class. |
Field Summary | |
---|---|
static String |
VERSION
Current version of this class. |
Constructor Summary | |
---|---|
SimpleHtmlParse(SimpleHtmlParse.Callback cb)
Constructs a SimpleHtmlParse object with a Callback object. |
Method Summary | |
---|---|
void |
collectElements(String content)
Evaluates the HTML document, passing each match to the Callback object for disposition. |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
---|
public static final String VERSION
Constructor Detail |
---|
public SimpleHtmlParse(SimpleHtmlParse.Callback cb)
SimpleHtmlParse.Callback
object determines what to do with
each structured item extracted.
cb
- a Callback object providing an
SimpleHtmlParse.Callback.addHtmlElement(java.lang.String, java.lang.String)
method for
disposition of each item.Method Detail |
---|
public void collectElements(String content)
content
- an HTML document represented as a String
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
CleanCode Java Libraries | Copyright © 2001-2012 Michael Sorens - Revised 2012.12.10 |