Parser Class

Used to parse HTML documents and fragments and find DOM elements

Constructors

Parser( String html )

Public Methods

getHTML( ) returns String
setHTML( String html ) returns void
Used to reset the "scope" of the parser
getElementByID( String id ) returns Element
Returns an HTML Element with a given id. Returns null if the element was not found.
getElementsByTagName( String tagName ) returns Element[]
Returns an array of HTML Elements found in the HTML document with given tag name.
getElements( ) returns Element[]
Returns an array of top-level HTML Elements found in the HTML document
getElements( String tagName, String attributeName, String attributeValue ) returns Element[]
Returns an array of HTML Elements found in the HTML document with given tag name, attribute, and attribute value (e.g. "div", "class", "hdr2").
getElementByTagName( String tagName ) returns Element
Returns the first HTML Element found in the HTML document with given tag name. Returns null if an element was not found.
getElementByAttributes( String tagName, String attributeName, String attributeValue ) returns Element
Returns the first HTML Element found in the HTML document with given tag name and attribute. Returns null if an element was not found.
getImageLinks( ) returns String[]
Returns a list of links to images. The links may include relative paths. Use the getAbsolutePath method to resolve the relative paths to a fully qualified url.

Static Methods

stripHTMLTags( String html ) returns String
Used to remove any html tags from a block of text
MapPath( String relPath, java.net.URL url ) returns String
Returns a fully qualified URL for a given path. Returns null if the function fails to resolve the path.
relPathRelative path to a file (e.g. "../images/header.jpg")
urlURL that is sourcing the relPath (e.g. "http://acme.com/about/")
getAbsolutePath( String relPath, String url ) returns String
Returns a fully qualified URL for a given path. See MapPath() method for more information.