我有一个字符串:
String HTMLtag="<xml><xslt><xhtml><whitespace><line-breaks>";
我想获得5个字符串:xml,xslt,xhtml,空格和换行符。
答案 0 :(得分:0)
像这样的东西
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);
}