简体   繁体   English

为什么不能Jsoup解析tagName“链接”

[英]why can't Jsoup parse tagName “link”

I have this wired senario within my Jsoup project 我在Jsoup项目中有这个有线的senario

here is how the HTML look like: 这是HTML的样子:

<html>
..

<link> example.com </link>
..

</html>

when I try to use Jsoup to get the text 当我尝试使用Jsoup来获取文本时

System.out.println(document.select("link").text()) ;//nothing gets printed. (it should print **example.com**)

but if I change the html into: 但如果我将html更改为:

<html>
..

<someOtherTage> example.com </someOtherTage>
..

</html>

then: 然后:

System.out.println(document.select("someOtherTage").text()); //prints **example.com**

So my question : 所以我的问题

Is this a bug in Jsoup or there is something especial about tag name " link "? 这是Jsoup一个错误还是有一些关于标记名称“ link ”的Jsoup

NOTE: Jsoup Version used 1.6 and 1.9. 注意: Jsoup版本使用1.6和1.9。 Java 7 and 8 Java 7和8

Since the link element is an empty element , JSoup has sanitized the element and moved its content into the body. 由于link元素是一个空元素 ,因此JSoup已对元素进行了清理并将其内容移动到了正文中。 (Verify this by printing the document). (通过打印文档进行验证)。

To keep the content in the link element, switch to XML parsing mode: 要将内容保留在link元素中,请切换到XML解析模式:

Document doc = Jsoup.parse(html, "", Parser.xmlParser());

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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