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
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.-
Constructor Summary
ConstructorsConstructorDescriptionTolerantSaxDocumentBuilder(DocumentBuilder documentBuilder) Constructor for specific JAXP parser -
Method Summary
Modifier and TypeMethodDescriptionvoidcharacters(char[] data, int start, int length) ContentHandler method.voidcomment(char[] ch, int start, int length) LexicalHandler methodvoidendCDATA()Unhandled LexicalHandler methodvoidContentHandler methodvoidendDTD()Unhandled LexicalHandler methodvoidendElement(String namespaceURI, String localName, String qName) ContentHandler methodvoidUnhandled LexicalHandler methodvoidendPrefixMapping(String prefix) Unhandled ContentHandler methodgetTrace()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 methodvoidUnhandled LexicalHandler methodvoidContentHandler methodvoidUnhandled LexicalHandler method.voidstartElement(String namespaceURI, String localName, String qName, Attributes atts) ContentHandler methodvoidstartEntity(String name) Unhandled LexicalHandler methodvoidstartPrefixMapping(String prefix, String uri) Unhandled ContentHandler methodMethods inherited from class org.xml.sax.helpers.DefaultHandler
error, fatalError, notationDecl, resolveEntity, unparsedEntityDecl, warningMethods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface org.xml.sax.ContentHandler
declaration
-
Constructor Details
-
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 Details
-
getDocument
- Returns:
- the Document built up through the Sax calls
-
getTrace
- Returns:
- the trace of Sax calls that were used to build up the Document
-
startDocument
ContentHandler method- Specified by:
startDocumentin interfaceContentHandler- Overrides:
startDocumentin classDefaultHandler- Throws:
SAXException
-
endDocument
ContentHandler 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
ContentHandler method- Specified by:
endElementin interfaceContentHandler- Overrides:
endElementin classDefaultHandler- Throws:
SAXException
-
endPrefixMapping
Unhandled ContentHandler method- Specified by:
endPrefixMappingin interfaceContentHandler- Overrides:
endPrefixMappingin classDefaultHandler- Throws:
SAXException
-
ignorableWhitespace
Unhandled ContentHandler method- Specified by:
ignorableWhitespacein interfaceContentHandler- Overrides:
ignorableWhitespacein classDefaultHandler- Throws:
SAXException
-
processingInstruction
ContentHandler method- Specified by:
processingInstructionin interfaceContentHandler- Overrides:
processingInstructionin classDefaultHandler- Throws:
SAXException
-
setDocumentLocator
Unhandled ContentHandler method- Specified by:
setDocumentLocatorin interfaceContentHandler- Overrides:
setDocumentLocatorin classDefaultHandler
-
skippedEntity
Unhandled ContentHandler method- Specified by:
skippedEntityin interfaceContentHandler- Overrides:
skippedEntityin classDefaultHandler- Throws:
SAXException
-
startPrefixMapping
Unhandled ContentHandler method- Specified by:
startPrefixMappingin interfaceContentHandler- Overrides:
startPrefixMappingin classDefaultHandler- Throws:
SAXException
-
startDTD
Unhandled LexicalHandler method. DOM currently doesn't allow DTD to be retrofitted onto a Document.- Specified by:
startDTDin interfaceLexicalHandler- Throws:
SAXException
-
endDTD
Unhandled LexicalHandler method- Specified by:
endDTDin interfaceLexicalHandler- Throws:
SAXException
-
startEntity
Unhandled LexicalHandler method- Specified by:
startEntityin interfaceLexicalHandler- Throws:
SAXException
-
endEntity
Unhandled LexicalHandler method- Specified by:
endEntityin interfaceLexicalHandler- Throws:
SAXException
-
startCDATA
Unhandled LexicalHandler method- Specified by:
startCDATAin interfaceLexicalHandler- Throws:
SAXException
-
endCDATA
Unhandled LexicalHandler method- Specified by:
endCDATAin interfaceLexicalHandler- Throws:
SAXException
-
comment
LexicalHandler method- Specified by:
commentin interfaceLexicalHandler- Throws:
SAXException
-