简体   繁体   中英

Parsing Java String with SGML

I have a Java String with SGML, something like this...

<misspell></misspell><plain>I</plain> <plain>know</plain> <plain>you</plain> <suggestion>ducky</suggestion> <plain>suck</plain> <plain>and</plain> <plain>I</plain> <plain>rocky</plain> <plain>rock</plain>

How do I parse it to get for instance say the text inside <suggestion> </suggestion> so as to get "ducky" out??

Will javax.swing.text.html.parser.Parse can be of any help? or I can only parse HTML docs with it?

The string you show is not HTML, but it could be parsed by an XML parser .

The SAX API is part of the JDK and AFAIK most XML parsers implement it.

try an html parser, they are (by necessity) quite forgiving of malformed markup and html is by nature based on SGML.

eg http://htmlparser.sourceforge.net/

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM