Parsing Java String with SGML

自古美人都是妖i 提交于 2019-12-12 02:19:15

问题


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?


回答1:


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.




回答2:


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

e.g. http://htmlparser.sourceforge.net/



来源:https://stackoverflow.com/questions/3193574/parsing-java-string-with-sgml

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!