用 jsoup 解析字符串

parse string with jsoup

我有一个字符串:

String HTMLtag="<xml><xslt><xhtml><whitespace><line-breaks>";

我想获取 5 个字符串:xml、xslt、xhtml、空格和换行符。

像这样

String html = "<xml><xslt><xhtml><whitespace><line-breaks>";
Document doc = Jsoup.parse(html, "", Parser.xmlParser());
for (Element e : doc.getAllElements()) {
    System.out.println(e.tagName());
}

输出

#root   --> This is the root element that is created by jsoup, you can ignore it.
xml
xslt
xhtml
whitespace
line-breaks

编辑

String html = "<xml><xslt><xhtml><whitespace><line-breaks>";
Document doc = Jsoup.parse(html, "", Parser.xmlParser());
for (Element e : doc.getAllElements()) {
    String tag = e.tagName();
    if(!tag.equalsIgnoreCase("#root"))
        System.out.println(tag);
}