org.custommonkey.xmlunit

Class TolerantSaxDocumentBuilder

public class TolerantSaxDocumentBuilder extends DefaultHandler implements LexicalHandler

Uses Sax events from the ContentHandler and LexicalHandler interfaces to build a DOM document in a tolerant fashion -- it can cope with start tags without end tags, and end tags without start tags for example. Although this subverts the idea of XML being well-formed, it is intended for use with HTML pages so that they can be transformed into DOM trees, without being XHTML to start with. Note that this class currently does not handle entity, DTD or CDATA tags.
Examples and more at xmlunit.sourceforge.net

See Also: HTMLDocumentBuilder

Constructor Summary
TolerantSaxDocumentBuilder(DocumentBuilder documentBuilder)
Constructor for specific JAXP parser
Method Summary
voidcharacters(char[] data, int start, int end)
ContentHandler method.
voidcomment(char[] ch, int start, int length)
LexicalHandler method
voidendCDATA()
Unhandled LexicalHandler method
voidendDocument()
ContentHandler method
voidendDTD()
Unhandled LexicalHandler method
voidendElement(String namespaceURI, String localName, String qName)
ContentHandler method
voidendEntity(String name)
Unhandled LexicalHandler method
voidendPrefixMapping(String prefix)
Unhandled ContentHandler method
DocumentgetDocument()
StringgetTrace()
voidignorableWhitespace(char[] ch, int start, int length)
Unhandled ContentHandler method
voidprocessingInstruction(String target, String data)
ContentHandler method
voidsetDocumentLocator(Locator locator)
Unhandled ContentHandler method
voidskippedEntity(String name)
Unhandled ContentHandler method
voidstartCDATA()
Unhandled LexicalHandler method
voidstartDocument()
ContentHandler method
voidstartDTD(String name, String publicId, String systemId)
Unhandled LexicalHandler method.
voidstartElement(String namespaceURI, String localName, String qName, Attributes atts)
ContentHandler method
voidstartEntity(String name)
Unhandled LexicalHandler method
voidstartPrefixMapping(String prefix, String uri)
Unhandled ContentHandler method

Constructor Detail

TolerantSaxDocumentBuilder

public TolerantSaxDocumentBuilder(DocumentBuilder documentBuilder)
Constructor for specific JAXP parser

Parameters: documentBuilder the JAXP parser to use to construct an empty DOM document that will be built up with SAX calls

Throws: ParserConfigurationException

Method Detail

characters

public void characters(char[] data, int start, int end)
ContentHandler method.

comment

public void comment(char[] ch, int start, int length)
LexicalHandler method

Throws: SAXException

endCDATA

public void endCDATA()
Unhandled LexicalHandler method

Throws: SAXException

endDocument

public void endDocument()
ContentHandler method

Throws: SAXException

endDTD

public void endDTD()
Unhandled LexicalHandler method

Throws: SAXException

endElement

public void endElement(String namespaceURI, String localName, String qName)
ContentHandler method

Throws: SAXException

endEntity

public void endEntity(String name)
Unhandled LexicalHandler method

Throws: SAXException

endPrefixMapping

public void endPrefixMapping(String prefix)
Unhandled ContentHandler method

Throws: SAXException

getDocument

public Document getDocument()

Returns: the Document built up through the Sax calls

getTrace

public String getTrace()

Returns: the trace of Sax calls that were used to build up the Document

ignorableWhitespace

public void ignorableWhitespace(char[] ch, int start, int length)
Unhandled ContentHandler method

Throws: SAXException

processingInstruction

public void processingInstruction(String target, String data)
ContentHandler method

Throws: SAXException

setDocumentLocator

public void setDocumentLocator(Locator locator)
Unhandled ContentHandler method

skippedEntity

public void skippedEntity(String name)
Unhandled ContentHandler method

Throws: SAXException

startCDATA

public void startCDATA()
Unhandled LexicalHandler method

Throws: SAXException

startDocument

public void startDocument()
ContentHandler method

Throws: SAXException

startDTD

public void startDTD(String name, String publicId, String systemId)
Unhandled LexicalHandler method. DOM currently doesn't allow DTD to be retrofitted onto a Document.

Throws: SAXException

startElement

public void startElement(String namespaceURI, String localName, String qName, Attributes atts)
ContentHandler method

Throws: SAXException

startEntity

public void startEntity(String name)
Unhandled LexicalHandler method

Throws: SAXException

startPrefixMapping

public void startPrefixMapping(String prefix, String uri)
Unhandled ContentHandler method

Throws: SAXException