tl  tr
  Home | Tutorials | Articles | Videos | Products | Tools | Search
Interviews | Open Source | Tag Cloud | Follow Us | Bookmark | Contact   
 Tools and Libs > Jsoup > Get and Set Value

Get and Set Value 

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 getting and setting the value of an input element.

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

File Name  :  
com/bethecoder/tutorials/jsoup/tests/GetAndSetValueTest.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;
import org.jsoup.nodes.Element;

public class GetAndSetValueTest {

  /**
   @param args
   @throws IOException 
   */
  public static void main(String[] argsthrows IOException {
    InputStream ins = GetAndSetValueTest.class.
        getClassLoader().getResourceAsStream("Simple2.html");
    
    Document doc = Jsoup.parse(ins, "UTF-8""btc.com");
    
    Element user = doc.getElementById("user");
    Element password = doc.getElementById("password");
    Element secret = doc.getElementById("secret");
    
    String mySecret = user.val() "@" + password.val();
    secret.val(mySecret.toLowerCase());
    
    System.out.println(doc.html());
  }

}
   

It gives the following output,
File Name  :  OUTPUT



 
  


  
bl  br