Package org.custommonkey.xmlunit
Class HTMLDocumentBuilder
- java.lang.Object
-
- org.custommonkey.xmlunit.HTMLDocumentBuilder
-
public class HTMLDocumentBuilder extends java.lang.ObjectBuild a DOM document from HTML content converting from 'plain' HTML into 'XHTML' along the way with the help of a TolerantSaxDocumentBuilder and the Swing html parser classes. This allows XML assertions to be made against badly formed HTML.- See Also:
TolerantSaxDocumentBuilder
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description classHTMLDocumentBuilder.SwingEvent2SaxAdapterAdapts Swing HTML callback messages to Sax equivalents, passing them to a Sax-aware ContentHandler.
-
Field Summary
Fields Modifier and Type Field Description protected HTMLDocumentBuilder.SwingEvent2SaxAdapterswingEvent2SaxAdapterThe adapter between Swing and SAX.protected TolerantSaxDocumentBuildertolerantSaxDocumentBuilderThe document builder.
-
Constructor Summary
Constructors Constructor Description HTMLDocumentBuilder(TolerantSaxDocumentBuilder tolerantSaxDocumentBuilder)Constructor
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description java.lang.StringgetTrace()org.w3c.dom.Documentparse(java.io.Reader reader)Parses the document.org.w3c.dom.Documentparse(java.lang.String htmlString)Parses the document.
-
-
-
Field Detail
-
tolerantSaxDocumentBuilder
protected final TolerantSaxDocumentBuilder tolerantSaxDocumentBuilder
The document builder.
-
swingEvent2SaxAdapter
protected final HTMLDocumentBuilder.SwingEvent2SaxAdapter swingEvent2SaxAdapter
The adapter between Swing and SAX.
-
-
Constructor Detail
-
HTMLDocumentBuilder
public HTMLDocumentBuilder(TolerantSaxDocumentBuilder tolerantSaxDocumentBuilder)
Constructor- Parameters:
tolerantSaxDocumentBuilder- the instance that will receive SAX calls generated as the HTML is parsed and build up a DOM Document
-
-
Method Detail
-
parse
public org.w3c.dom.Document parse(java.io.Reader reader) throws org.xml.sax.SAXException, java.io.IOExceptionParses the document.Not thread-safe!
- Parameters:
reader- reader to read the document from- Returns:
- a DOM document parsed from the Reader via an SwingEvent2SaxAdapter and TolerantSaxBuilder.
- Throws:
org.xml.sax.SAXException- if the parser feels like itjava.io.IOException- on I/O errors- See Also:
TolerantSaxDocumentBuilder
-
parse
public org.w3c.dom.Document parse(java.lang.String htmlString) throws org.xml.sax.SAXException, java.io.IOExceptionParses the document.Not thread-safe!
- Parameters:
htmlString- string to read the document from- Returns:
- a DOM document parsed from the String via an SwingEvent2SaxAdapter and TolerantSaxBuilder.
- Throws:
org.xml.sax.SAXException- if the parser feels like itjava.io.IOException- on I/O errors- See Also:
TolerantSaxDocumentBuilder
-
getTrace
public java.lang.String getTrace()
- Returns:
- the trace of events and / or warnings encountered during parsing
-
-