本文整理了Java中org.jsoup.nodes.Document.childNodeSize()
方法的一些代码示例,展示了Document.childNodeSize()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Document.childNodeSize()
方法的具体详情如下:
包路径:org.jsoup.nodes.Document
类名称:Document
方法名:childNodeSize
暂无
代码示例来源:origin: org.jsoup/jsoup
void insert(Token.Comment commentToken) {
Comment comment = new Comment(commentToken.getData());
Node insert = comment;
if (commentToken.bogus) { // xml declarations are emitted as bogus comments (which is right for html, but not xml)
// so we do a bit of a hack and parse the data as an element to pull the attributes out
String data = comment.getData();
if (data.length() > 1 && (data.startsWith("!") || data.startsWith("?"))) {
Document doc = Jsoup.parse("<" + data.substring(1, data.length() -1) + ">", baseUri, Parser.xmlParser());
if (doc.childNodeSize() > 0) {
Element el = doc.child(0);
insert = new XmlDeclaration(settings.normalizeTag(el.tagName()), data.startsWith("!"));
insert.attributes().addAll(el.attributes());
} // else, we couldn't parse it as a decl, so leave as a comment
}
}
insertNode(insert);
}
代码示例来源:origin: org.jsoup/jsoup
if (foundCharset == null && doc.childNodeSize() > 0 && doc.childNode(0) instanceof XmlDeclaration) {
XmlDeclaration prolog = (XmlDeclaration) doc.childNode(0);
if (prolog.name().equals("xml"))
代码示例来源:origin: chimbori/crux
@Test
public void testRetainSpaceInsideTags() {
final String As = "aaa aaa aaa aaa aaa aaa aaa aaa aaa aaa aaa aaa aaa aaa aaa aaa aaa aaa aaa aaa aaa aaa";
final String Bs = "bbb bbb bbb bbb bbb bbb bbb bbb bbb bbb bbb bbb bbb bbb bbb bbb bbb bbb bbb bbb bbb bbb";
final String Cs = "ccc ccc ccc ccc ccc ccc ccc ccc ccc ccc ccc ccc ccc ccc ccc ccc ccc ccc ccc ccc ccc ccc";
Article article = ArticleExtractor.with(EXAMPLE_URL, String.format("<html><body><div> %s <p> %s</p>%s </div></body></html>", As, Bs, Cs)).extractContent().article();
assertEquals(3, article.document.childNodeSize());
assertEquals(As, article.document.childNode(0).outerHtml().trim());
assertEquals(String.format("<p> %s</p>", Bs), article.document.childNode(1).outerHtml().trim());
assertEquals(Cs, article.document.childNode(2).outerHtml().trim());
article = ArticleExtractor.with(EXAMPLE_URL, String.format("<html><body><div> %s <p>%s </p>%s</div></body></html>", As, Bs, Cs)).extractContent().article();
assertEquals(3, article.document.childNodeSize());
assertEquals(As, article.document.childNode(0).outerHtml().trim());
assertEquals(String.format("<p>%s </p>", Bs), article.document.childNode(1).outerHtml().trim());
assertEquals(Cs, article.document.childNode(2).outerHtml().trim());
article = ArticleExtractor.with(EXAMPLE_URL, String.format("<html><body><div> %s <p> %s </p>%s</div></body></html>", As, Bs, Cs)).extractContent().article();
assertEquals(3, article.document.childNodeSize());
assertEquals(As, article.document.childNode(0).outerHtml().trim());
assertEquals(String.format("<p> %s </p>", Bs), article.document.childNode(1).outerHtml().trim());
assertEquals(Cs, article.document.childNode(2).outerHtml().trim());
}
内容来源于网络,如有侵权,请联系作者删除!