本文整理了Java中org.jsoup.nodes.Element.childNodes()
方法的一些代码示例,展示了Element.childNodes()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Element.childNodes()
方法的具体详情如下:
包路径:org.jsoup.nodes.Element
类名称:Element
方法名:childNodes
暂无
代码示例来源:origin: org.jsoup/jsoup
@Override
public boolean matches(Element root, Element element) {
List<Node> family = element.childNodes();
for (Node n : family) {
if (!(n instanceof Comment || n instanceof XmlDeclaration || n instanceof DocumentType)) return false;
}
return true;
}
@Override
代码示例来源:origin: stackoverflow.com
Element td = getItSomehow();
for (Node child : td.childNodes()) {
if (child instanceof TextNode) {
System.out.println(((TextNode) child).text());
}
}
代码示例来源:origin: code4craft/webmagic
protected String getText(Element element) {
StringBuilder accum = new StringBuilder();
for (Node node : element.childNodes()) {
if (node instanceof TextNode) {
TextNode textNode = (TextNode) node;
accum.append(textNode.text());
}
}
return accum.toString();
}
代码示例来源:origin: stackoverflow.com
String url = "http://www.latijnengrieks.com/vertaling.php?id=5368";
Document document = Jsoup.parse(new URL(url).openStream(), "ISO-8859-1", url);
Element paragraph = document.select("div.kader p").first();
for (Node node : paragraph.childNodes()) {
if (node instanceof TextNode) {
System.out.println(((TextNode) node).text().trim());
}
}
代码示例来源:origin: jooby-project/jooby
/**
* Read a svg file and return the svg element (original) and a new symbol element (created from
* original).
*
* @param file Svg file.
* @param id ID to use.
* @return Svg element (original) and a symbol element (converted).
* @throws IOException If something goes wrong.
*/
private Tuple<Element, Element> symbol(final Path file, final String id) throws IOException {
Element svg = Jsoup.parse(file.toFile(), "UTF-8").select("svg").first();
Element symbol = new Element(Tag.valueOf("symbol"), "")
.attr("id", id)
.attr("viewBox", svg.attr("viewBox"));
new ArrayList<>(svg.childNodes()).forEach(symbol::appendChild);
return new Tuple(svg, symbol);
}
代码示例来源:origin: JpressProjects/jpress
/**
* 剩下的数据 按照左侧无空格方式处理生成Nodes
*
* @param lineHtml
* @param liNode
* @param jsonNodes
*/
private void processLiWithoutLeftWhiteSpace(String lineHtml, JSONObject liNode, JSONArray jsonNodes) {
List<Node> nodes = Jsoup.parse(lineHtml).selectFirst("body").childNodes();
if (nodes.isEmpty()) {
liNode.put("nodes", Collections.emptyList());
} else {
JSONObject jsonObject = null;
for (Node node : nodes) {
String tag = node.nodeName();
if (isTextNode(tag)) {
processMutilTextNode(jsonNodes, tag, ((TextNode) node).getWholeText());
} else {
if (isNotNullSpan(node)) {
jsonObject = convertNodeToJsonObject(node, node.nodeName(), true);
if (jsonObject != null) {
jsonNodes.add(jsonObject);
}
}
}
}
liNode.put("nodes", jsonNodes);
}
}
代码示例来源:origin: org.jsoup/jsoup
/**
Determines if the input document <b>body</b>is valid, against the whitelist. It is considered valid if all the tags and attributes
in the input HTML are allowed by the whitelist, and that there is no content in the <code>head</code>.
<p>
This method can be used as a validator for user input. An invalid document will still be cleaned successfully
using the {@link #clean(Document)} document. If using as a validator, it is recommended to still clean the document
to ensure enforced attributes are set correctly, and that the output is tidied.
</p>
@param dirtyDocument document to test
@return true if no tags or attributes need to be removed; false if they do
*/
public boolean isValid(Document dirtyDocument) {
Validate.notNull(dirtyDocument);
Document clean = Document.createShell(dirtyDocument.baseUri());
int numDiscarded = copySafeNodes(dirtyDocument.body(), clean.body());
return numDiscarded == 0
&& dirtyDocument.head().childNodes().size() == 0; // because we only look at the body, but we start from a shell, make sure there's nothing in the head
}
代码示例来源:origin: JpressProjects/jpress
List<Node> nodes = document.body().childNodes();
代码示例来源:origin: org.jsoup/jsoup
return root.childNodes();
else
return doc.childNodes();
代码示例来源:origin: org.jsoup/jsoup
Node[] childNodes = furthestBlock.childNodes().toArray(new Node[furthestBlock.childNodeSize()]);
for (Node childNode : childNodes) {
代码示例来源:origin: stackoverflow.com
public static void main(String[] args) throws IOException {
String str = "<div>" +
" Some text <b>with tags</b> might go here." +
" <p>Also there are paragraphs</p>" +
" More text can go without paragraphs<br/>" +
"</div>";
Document doc = Jsoup.parse(str);
Element div = doc.select("div").first();
int i = 0;
for (Node node : div.childNodes()) {
i++;
System.out.println(String.format("%d %s %s",
i,
node.getClass().getSimpleName(),
node.toString()));
}
}
代码示例来源:origin: com.vaadin/vaadin-server
/**
* Clears the children and attributes of the given element.
*
* @param design
* the element to be cleared
*/
public static void clearElement(Element design) {
Attributes attr = design.attributes();
for (Attribute a : attr.asList()) {
attr.remove(a.getKey());
}
List<Node> children = new ArrayList<>();
children.addAll(design.childNodes());
for (Node node : children) {
node.remove();
}
}
代码示例来源:origin: com.vaadin/vaadin-server
@Override
public void readDesign(Element design, DesignContext designContext) {
super.readDesign(design, designContext);
String altText = "";
for (Node child : design.childNodes()) {
if (child instanceof Element
&& ((Element) child).tagName().equals("source")
&& child.hasAttr("href")) {
addSource(DesignAttributeHandler.readAttribute("href",
child.attributes(), Resource.class));
} else {
altText += child.toString();
}
}
altText = altText.trim();
if (!altText.isEmpty()) {
setAltText(altText);
}
}
代码示例来源:origin: com.vaadin/vaadin-server
@Override
public void readDesign(Element design, DesignContext designContext) {
// Read content first to avoid NPE when setting popup visible
Component popupContent = null;
String minimizedValue = "";
for (Node childNode : design.childNodes()) {
if (childNode instanceof Element) {
Element child = (Element) childNode;
if (child.tagName().equals("popup-content")) {
popupContent = designContext.readDesign(child.child(0));
} else {
minimizedValue += child.toString();
}
} else {
minimizedValue += childNode.toString();
}
}
setContent(createContent(minimizedValue.trim(), popupContent));
super.readDesign(design, designContext);
}
代码示例来源:origin: com.vaadin/vaadin-server
return;
for (Node child : head.childNodes()) {
if (child instanceof Element) {
Element childElement = (Element) child;
代码示例来源:origin: stackoverflow.com
for(Element e : doc.getAllElements()){
for(Node n: e.childNodes()){
if(n instanceof Comment){
System.out.println(n);
}
}
}
代码示例来源:origin: com.vaadin/vaadin-server
for (Node node : menuElement.childNodes()) {
if (node instanceof Element
&& ((Element) node).tagName().equals("menu")) {
代码示例来源:origin: us.codecraft/webmagic-core
protected String getText(Element element) {
StringBuilder accum = new StringBuilder();
for (Node node : element.childNodes()) {
if (node instanceof TextNode) {
TextNode textNode = (TextNode) node;
accum.append(textNode.text());
}
}
return accum.toString();
}
代码示例来源:origin: stackoverflow.com
String html = "<span style=\"font-weight:bold;\">bold.</span><span></span><span><a>text</a></span>";
Document parsedDoc = Jsoup.parse(html);
Elements selects = parsedDoc.select("span");
for (Element span : selects) {
List<Node> childNodes = span.childNodes();
if (childNodes.size() > 0 && span.childNode(0).childNodes().size() == 0) {
span.childNode(0).wrap("<p>");
}
}
代码示例来源:origin: org.eclipse.mylyn.docs/org.eclipse.mylyn.wikitext
private void removeElementPreserveChildren(Element element) {
final Element parent = element.parent();
for (Node child : new ArrayList<Node>(element.childNodes())) {
child.remove();
element.before(child);
}
element.remove();
if (parent != null) {
normalizeTextNodes(parent);
}
}
}
内容来源于网络,如有侵权,请联系作者删除!