tl  tr
  Home | Tutorials | Articles | Videos | Products | Tools | Search
Interviews | Open Source | Tag Cloud | Follow Us | Bookmark | Contact   
 Tools and Libs > Jsoup > Remove all Child Nodes

Remove all Child Nodes 

Jsoup is an open source java library for parsing and manipulating HTML with ease. Get the latest binaries from http://jsoup.org/. This requires the library jsoup-1.6.1.jar to be in classpath. The following example shows removing all child nodes from a particular element.

File Name  :  
/JSOUP001/config/html/Simple2.html 

File Name  :  
com/bethecoder/tutorials/jsoup/tests/EmptyTest.java 
Author  :  Sudhakar KV
Email  :  [email protected]
   
package com.bethecoder.tutorials.jsoup.tests;

import java.io.IOException;
import java.io.InputStream;

import org.jsoup.Jsoup;
import org.jsoup.nodes.Document;

public class EmptyTest {

  /**
   @param args
   @throws IOException 
   */
  public static void main(String[] argsthrows IOException {
    InputStream ins = EmptyTest.class.
        getClassLoader().getResourceAsStream("Simple2.html");
    
    Document doc = Jsoup.parse(ins, "UTF-8""btc.com");
    doc.body().empty()//Remove all of the element's child nodes
    
    System.out.println(doc.html());
  }

}
   

It gives the following output,
File Name  :  OUTPUT



 
  


  
bl  br