Java Code Examples for org.jsoup.nodes.Comment

The following examples show how to use org.jsoup.nodes.Comment. These examples are extracted from open source projects. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source Project: flow   Source File: JsoupUtils.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * Removes all comments from the {@code node} tree.
 *
 * @param node
 *            a Jsoup node
 */
static void removeCommentsRecursively(Node node) {
    int i = 0;
    while (i < node.childNodeSize()) {
        Node child = node.childNode(i);
        if (child instanceof Comment) {
            child.remove();
        } else {
            removeCommentsRecursively(child);
            i++;
        }
    }
}
 
Example 2
Source Project: compiler   Source File: HtmlVisitor.java    License: Apache License 2.0 5 votes vote down vote up
public void visit(org.jsoup.nodes.Comment node) {
		boa.types.Ast.Comment.Builder b = boa.types.Ast.Comment.newBuilder();
		b.setKind(CommentKind.OTHER);// FIXME
		b.setValue(node.getData());
//		b.setPosition(node.) FIXME
		comments.add(b.build());
	}
 
Example 3
Source Project: astor   Source File: Evaluator.java    License: GNU General Public License v2.0 5 votes vote down vote up
@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;
}
 
Example 4
Source Project: astor   Source File: Evaluator.java    License: GNU General Public License v2.0 5 votes vote down vote up
@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;
}
 
Example 5
Source Project: astor   Source File: HtmlParserTest.java    License: GNU General Public License v2.0 5 votes vote down vote up
@Test public void parsesComments() {
    String html = "<html><head></head><body><img src=foo><!-- <table><tr><td></table> --><p>Hello</p></body></html>";
    Document doc = Jsoup.parse(html);

    Element body = doc.body();
    Comment comment = (Comment) body.childNode(1); // comment should not be sub of img, as it's an empty tag
    assertEquals(" <table><tr><td></table> ", comment.getData());
    Element p = body.child(1);
    TextNode text = (TextNode) p.childNode(0);
    assertEquals("Hello", text.getWholeText());
}
 
Example 6
Source Project: astor   Source File: Evaluator.java    License: GNU General Public License v2.0 5 votes vote down vote up
@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;
}
 
Example 7
Source Project: astor   Source File: HtmlParserTest.java    License: GNU General Public License v2.0 5 votes vote down vote up
@Test public void parsesComments() {
    String html = "<html><head></head><body><img src=foo><!-- <table><tr><td></table> --><p>Hello</p></body></html>";
    Document doc = Jsoup.parse(html);

    Element body = doc.body();
    Comment comment = (Comment) body.childNode(1); // comment should not be sub of img, as it's an empty tag
    assertEquals(" <table><tr><td></table> ", comment.getData());
    Element p = body.child(1);
    TextNode text = (TextNode) p.childNode(0);
    assertEquals("Hello", text.getWholeText());
}
 
Example 8
Source Project: jsoup-learning   Source File: Evaluator.java    License: MIT License 5 votes vote down vote up
@Override
public boolean matches(Element root, Element element) {
      	List<Node> family = element.childNodes();
      	for (int i = 0; i < family.size(); i++) {
      		Node n = family.get(i);
      		if (!(n instanceof Comment || n instanceof XmlDeclaration || n instanceof DocumentType)) return false; 
      	}
      	return true;
}
 
Example 9
Source Project: astor   Source File: HtmlTreeBuilder.java    License: GNU General Public License v2.0 4 votes vote down vote up
void insert(Token.Comment commentToken) {
    Comment comment = new Comment(commentToken.getData());
    insertNode(comment);
}
 
Example 10
Source Project: astor   Source File: HtmlTreeBuilder.java    License: GNU General Public License v2.0 4 votes vote down vote up
void insert(Token.Comment commentToken) {
    Comment comment = new Comment(commentToken.getData());
    insertNode(comment);
}