Here is my sample input HTML Codes:
<html>
<head>
<object></object>
</head>
<body>
</body>
</html>
Below is the output when parsed using Jsoup:
<html>
<head>
</head>
<body>
<object></object>
</body>
</html>
Question: Why did Jsoup move the <object>
tag from the <head>
to the <body>
?
This is correct behaviour since <object>
must appear inside the body.
HTML Tag
[...]
Tips and Notes
Note: An element must appear inside the 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
If you want the object within the head, you can use the XmlParser
instead:
final String html = "<html>\n"
+ "<head>\n"
+ "<object></object>\n"
+ "</head>\n"
+ "<body>\n"
+ "</body>\n"
+ "</html>";
Document doc = Jsoup.parse(html, "", Parser.xmlParser());
// |<-------------->|
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.