Html Structure Varying On Input
I have a string which contains dynamic HTML. The HTML can contain static image, maps, texts, links, etc. You can take a look at this link.  The answer to this question is working w
Solution 1:
Reading your original question I see that you can achieve what you want this way:
- You have an anchor (
a.favorite) - You have to pick his grandchild (
fontin this particular case, but it could be animgor whatever) - You delete the children of the original anchor
 - and then you append the grandchildren as a new child!.
 
This may sound complicated but it is very easy, here you are a code example:
String html ="<a class=\"favourite\" href=\"LixWQfueLU\"><a href=\"LixWQfueLU\"><font color=\"#009a49\">Rohit Lalwani</font></a></a>";
    Document doc =Jsoup.parse(html);
    //The original anchorElement afav = doc.select(".favourite").first();
    //The grandchildElement select = doc.select("font").first();
    afav.remove();
    afav.appendChild(select);
    System.out.println(afav);
Output:
<aclass="favourite"href="LixWQfueLU"><fontcolor="#009a49">Rohit Lalwani</font></a>Hope it helps!
Post a Comment for "Html Structure Varying On Input"