0

I am working on a java rcp application. Whenever user updates the details in UI, we are suppose to update the same details in html report also. Is there a we can update/add the html elements using java. Using Jsoup I am able to get the required element ID, but not able to innert/update new element to it.

Document htmlFile = null;

    try {
        htmlFile = Jsoup.parse(new File("C:\\ItemDetails1.html"), "UTF-8");
    } catch (IOException e) {
        e.printStackTrace();
    }
    Element div = htmlFile.getElementById("row2_comment");
    System.out.println("text: " + div.html());
    div.html("<li><b>Comments</b></li><ul><li>Testing for comment</li></ul>");

Any thoughts

1 Answer 1

2
Try:

Element div = 
 htmlFile.getElementById("row2_comment");

 div.appendElement("p").attr("class", 
 "beautiful").text("Some New Text")

To add a new paragraph with some style and text content

Sign up to request clarification or add additional context in comments.

2 Comments

This updates the div element in the memory, but not on actual html file. When I closed and reopened the file, I do not see any changes.
To save the file: File input = new File("C:\\ItemDetails1.html"); PrintWriter writer = new PrintWriter(input,"UTF-8"); then make modfications and :writer.write(htmlFile.html() ) ; writer.flush(); writer.close();

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.