Class HTMLDocumentBuilder

java.lang.Object
org.custommonkey.xmlunit.HTMLDocumentBuilder

public class HTMLDocumentBuilder extends Object
Build 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:
  • Field Details

  • Constructor Details

    • 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 Details

    • parse

      public Document parse(Reader reader) throws SAXException, IOException
      Parses 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:
      SAXException - if the parser feels like it
      IOException - on I/O errors
      See Also:
    • parse

      public Document parse(String htmlString) throws SAXException, IOException
      Parses 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:
      SAXException - if the parser feels like it
      IOException - on I/O errors
      See Also:
    • getTrace

      public String getTrace()
      Returns:
      the trace of events and / or warnings encountered during parsing