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
ConstructorDescriptionTolerantSaxDocumentBuilder
(DocumentBuilder documentBuilder) Constructor for specific JAXP parser -
Method Summary
Modifier and TypeMethodDescriptionvoid
characters
(char[] data, int start, int length) ContentHandler method.void
comment
(char[] ch, int start, int length) LexicalHandler methodvoid
endCDATA()
Unhandled LexicalHandler methodvoid
ContentHandler methodvoid
endDTD()
Unhandled LexicalHandler methodvoid
endElement
(String namespaceURI, String localName, String qName) ContentHandler methodvoid
Unhandled LexicalHandler methodvoid
endPrefixMapping
(String prefix) Unhandled ContentHandler methodgetTrace()
void
ignorableWhitespace
(char[] ch, int start, int length) Unhandled ContentHandler methodvoid
processingInstruction
(String target, String data) ContentHandler methodvoid
setDocumentLocator
(Locator locator) Unhandled ContentHandler methodvoid
skippedEntity
(String name) Unhandled ContentHandler methodvoid
Unhandled LexicalHandler methodvoid
ContentHandler methodvoid
Unhandled LexicalHandler method.void
startElement
(String namespaceURI, String localName, String qName, Attributes atts) ContentHandler methodvoid
startEntity
(String name) Unhandled LexicalHandler methodvoid
startPrefixMapping
(String prefix, String uri) Unhandled ContentHandler methodMethods inherited from class org.xml.sax.helpers.DefaultHandler
error, fatalError, notationDecl, resolveEntity, unparsedEntityDecl, warning
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
Methods 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:
startDocument
in interfaceContentHandler
- Overrides:
startDocument
in classDefaultHandler
- Throws:
SAXException
-
endDocument
ContentHandler method- Specified by:
endDocument
in interfaceContentHandler
- Overrides:
endDocument
in classDefaultHandler
- Throws:
SAXException
-
characters
public void characters(char[] data, int start, int length) ContentHandler method.- Specified by:
characters
in interfaceContentHandler
- Overrides:
characters
in classDefaultHandler
-
startElement
public void startElement(String namespaceURI, String localName, String qName, Attributes atts) throws SAXException ContentHandler method- Specified by:
startElement
in interfaceContentHandler
- Overrides:
startElement
in classDefaultHandler
- Throws:
SAXException
-
endElement
ContentHandler method- Specified by:
endElement
in interfaceContentHandler
- Overrides:
endElement
in classDefaultHandler
- Throws:
SAXException
-
endPrefixMapping
Unhandled ContentHandler method- Specified by:
endPrefixMapping
in interfaceContentHandler
- Overrides:
endPrefixMapping
in classDefaultHandler
- Throws:
SAXException
-
ignorableWhitespace
Unhandled ContentHandler method- Specified by:
ignorableWhitespace
in interfaceContentHandler
- Overrides:
ignorableWhitespace
in classDefaultHandler
- Throws:
SAXException
-
processingInstruction
ContentHandler method- Specified by:
processingInstruction
in interfaceContentHandler
- Overrides:
processingInstruction
in classDefaultHandler
- Throws:
SAXException
-
setDocumentLocator
Unhandled ContentHandler method- Specified by:
setDocumentLocator
in interfaceContentHandler
- Overrides:
setDocumentLocator
in classDefaultHandler
-
skippedEntity
Unhandled ContentHandler method- Specified by:
skippedEntity
in interfaceContentHandler
- Overrides:
skippedEntity
in classDefaultHandler
- Throws:
SAXException
-
startPrefixMapping
Unhandled ContentHandler method- Specified by:
startPrefixMapping
in interfaceContentHandler
- Overrides:
startPrefixMapping
in classDefaultHandler
- Throws:
SAXException
-
startDTD
Unhandled LexicalHandler method. DOM currently doesn't allow DTD to be retrofitted onto a Document.- Specified by:
startDTD
in interfaceLexicalHandler
- Throws:
SAXException
-
endDTD
Unhandled LexicalHandler method- Specified by:
endDTD
in interfaceLexicalHandler
- Throws:
SAXException
-
startEntity
Unhandled LexicalHandler method- Specified by:
startEntity
in interfaceLexicalHandler
- Throws:
SAXException
-
endEntity
Unhandled LexicalHandler method- Specified by:
endEntity
in interfaceLexicalHandler
- Throws:
SAXException
-
startCDATA
Unhandled LexicalHandler method- Specified by:
startCDATA
in interfaceLexicalHandler
- Throws:
SAXException
-
endCDATA
Unhandled LexicalHandler method- Specified by:
endCDATA
in interfaceLexicalHandler
- Throws:
SAXException
-
comment
LexicalHandler method- Specified by:
comment
in interfaceLexicalHandler
- Throws:
SAXException
-