How to use JAXB with HTML?

后端 未结 1 1338
隐瞒了意图╮
隐瞒了意图╮ 2021-01-14 13:17

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

相关标签:
1条回答
  • 2021-01-14 13:22

    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:

    • http://blog.bdoughan.com/2011/05/jaxb-and-dtd.html
    0 讨论(0)
提交回复
热议问题