Package org.custommonkey.xmlunit
Class TolerantSaxDocumentBuilder
- java.lang.Object
-
- org.xml.sax.helpers.DefaultHandler
-
- org.custommonkey.xmlunit.TolerantSaxDocumentBuilder
-
- All Implemented Interfaces:
ContentHandler,DTDHandler,EntityResolver,ErrorHandler,LexicalHandler
public class TolerantSaxDocumentBuilder extends DefaultHandler implements LexicalHandler
Uses Sax events from theContentHandlerandLexicalHandlerinterfaces 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.
-
-
Constructor Summary
Constructors Constructor Description TolerantSaxDocumentBuilder(DocumentBuilder documentBuilder)Constructor for specific JAXP parser
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidcharacters(char[] data, int start, int length)ContentHandler method.voidcomment(char[] ch, int start, int length)LexicalHandler methodvoidendCDATA()Unhandled LexicalHandler methodvoidendDocument()ContentHandler methodvoidendDTD()Unhandled LexicalHandler methodvoidendElement(String namespaceURI, String localName, String qName)ContentHandler methodvoidendEntity(String name)Unhandled LexicalHandler methodvoidendPrefixMapping(String prefix)Unhandled ContentHandler methodDocumentgetDocument()StringgetTrace()voidignorableWhitespace(char[] ch, int start, int length)Unhandled ContentHandler methodvoidprocessingInstruction(String target, String data)ContentHandler methodvoidsetDocumentLocator(Locator locator)Unhandled ContentHandler methodvoidskippedEntity(String name)Unhandled ContentHandler methodvoidstartCDATA()Unhandled LexicalHandler methodvoidstartDocument()ContentHandler methodvoidstartDTD(String name, String publicId, String systemId)Unhandled LexicalHandler method.voidstartElement(String namespaceURI, String localName, String qName, Attributes atts)ContentHandler methodvoidstartEntity(String name)Unhandled LexicalHandler methodvoidstartPrefixMapping(String prefix, String uri)Unhandled ContentHandler method-
Methods inherited from class org.xml.sax.helpers.DefaultHandler
error, fatalError, notationDecl, resolveEntity, unparsedEntityDecl, warning
-
-
-
-
Constructor Detail
-
TolerantSaxDocumentBuilder
public TolerantSaxDocumentBuilder(DocumentBuilder documentBuilder) throws ParserConfigurationException
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- if JAXP feels like it
-
-
Method Detail
-
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
-
startDocument
public void startDocument() throws SAXExceptionContentHandler method- Specified by:
startDocumentin interfaceContentHandler- Overrides:
startDocumentin classDefaultHandler- Throws:
SAXException
-
endDocument
public void endDocument() throws SAXExceptionContentHandler method- Specified by:
endDocumentin interfaceContentHandler- Overrides:
endDocumentin classDefaultHandler- Throws:
SAXException
-
characters
public void characters(char[] data, int start, int length)ContentHandler method.- Specified by:
charactersin interfaceContentHandler- Overrides:
charactersin classDefaultHandler
-
startElement
public void startElement(String namespaceURI, String localName, String qName, Attributes atts) throws SAXException
ContentHandler method- Specified by:
startElementin interfaceContentHandler- Overrides:
startElementin classDefaultHandler- Throws:
SAXException
-
endElement
public void endElement(String namespaceURI, String localName, String qName) throws SAXException
ContentHandler method- Specified by:
endElementin interfaceContentHandler- Overrides:
endElementin classDefaultHandler- Throws:
SAXException
-
endPrefixMapping
public void endPrefixMapping(String prefix) throws SAXException
Unhandled ContentHandler method- Specified by:
endPrefixMappingin interfaceContentHandler- Overrides:
endPrefixMappingin classDefaultHandler- Throws:
SAXException
-
ignorableWhitespace
public void ignorableWhitespace(char[] ch, int start, int length) throws SAXExceptionUnhandled ContentHandler method- Specified by:
ignorableWhitespacein interfaceContentHandler- Overrides:
ignorableWhitespacein classDefaultHandler- Throws:
SAXException
-
processingInstruction
public void processingInstruction(String target, String data) throws SAXException
ContentHandler method- Specified by:
processingInstructionin interfaceContentHandler- Overrides:
processingInstructionin classDefaultHandler- Throws:
SAXException
-
setDocumentLocator
public void setDocumentLocator(Locator locator)
Unhandled ContentHandler method- Specified by:
setDocumentLocatorin interfaceContentHandler- Overrides:
setDocumentLocatorin classDefaultHandler
-
skippedEntity
public void skippedEntity(String name) throws SAXException
Unhandled ContentHandler method- Specified by:
skippedEntityin interfaceContentHandler- Overrides:
skippedEntityin classDefaultHandler- Throws:
SAXException
-
startPrefixMapping
public void startPrefixMapping(String prefix, String uri) throws SAXException
Unhandled ContentHandler method- Specified by:
startPrefixMappingin interfaceContentHandler- Overrides:
startPrefixMappingin classDefaultHandler- Throws:
SAXException
-
startDTD
public void startDTD(String name, String publicId, String systemId) throws SAXException
Unhandled LexicalHandler method. DOM currently doesn't allow DTD to be retrofitted onto a Document.- Specified by:
startDTDin interfaceLexicalHandler- Throws:
SAXException
-
endDTD
public void endDTD() throws SAXExceptionUnhandled LexicalHandler method- Specified by:
endDTDin interfaceLexicalHandler- Throws:
SAXException
-
startEntity
public void startEntity(String name) throws SAXException
Unhandled LexicalHandler method- Specified by:
startEntityin interfaceLexicalHandler- Throws:
SAXException
-
endEntity
public void endEntity(String name) throws SAXException
Unhandled LexicalHandler method- Specified by:
endEntityin interfaceLexicalHandler- Throws:
SAXException
-
startCDATA
public void startCDATA() throws SAXExceptionUnhandled LexicalHandler method- Specified by:
startCDATAin interfaceLexicalHandler- Throws:
SAXException
-
endCDATA
public void endCDATA() throws SAXExceptionUnhandled LexicalHandler method- Specified by:
endCDATAin interfaceLexicalHandler- Throws:
SAXException
-
comment
public void comment(char[] ch, int start, int length) throws SAXExceptionLexicalHandler method- Specified by:
commentin interfaceLexicalHandler- Throws:
SAXException
-
-