I would like to unmarshall some nasty HTML to a Java object using JAXB. (I\'m on Java 7).
Tagsoup is a SAX-compliant XML parser that can handle nasty HTML.
H
You can get an UnmarshallerHandler
from an Unmarshaller
and set that as the ContentHandler
on your SAX parser. After you do the SAX parse obtain the object from the UnmarshallerHandler
.
UnmarshallerHandler unmarshallerHandler = unmarshaller.getUnmarshallerHandler();
xmlReader.setContentHandler(unmarshallerHandler);
xmlReader.parse(...);
Thing thing = (Thing) unmarshallerHandler.getResult();
There is an example of this on my blog: