[英]Why did Jsoup move an HTML element when it was parsed?
Here is my sample input HTML Codes: 这是我的示例输入HTML代码:
<html>
<head>
<object></object>
</head>
<body>
</body>
</html>
Below is the output when parsed using Jsoup: 以下是使用Jsoup解析时的输出:
<html>
<head>
</head>
<body>
<object></object>
</body>
</html>
Question: Why did Jsoup move the <object>
tag from the <head>
to the <body>
? 问题:为什么Jsoup为什么将
<object>
标记从<head>
移到<body>
?
This is correct behaviour since <object>
must appear inside the body. 这是正确的行为,因为
<object>
必须出现在体内。
HTML Tag
HTML标签
[...]
[...]
Tips and Notes
提示和注意事项
Note: An element must appear inside the element .
注意:元素必须出现在element内部 。 The text between the and is an alternate text, for browsers that do not support this tag.
和之间的文本是备用文本,用于不支持此标记的浏览器。
http://www.w3schools.com/tags/tag_object.asp http://www.w3schools.com/tags/tag_object.asp
If you want the object within the head, you can use the XmlParser
instead: 如果要将对象放在头部,则可以使用
XmlParser
代替:
final String html = "<html>\n"
+ "<head>\n"
+ "<object></object>\n"
+ "</head>\n"
+ "<body>\n"
+ "</body>\n"
+ "</html>";
Document doc = Jsoup.parse(html, "", Parser.xmlParser());
// |<-------------->|
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.