Reputation: 179
I have read the content of HTML into string, now I need to add a new attribute inside the body tag, I was thinking of using StringBuilder for this. But I am unable to frame the logic. Any help would be really appreciated.
Existing HTML
<body class="temporaryrevision">
HTML that I want to create
<body class="temporaryrevision" bgcolor="#FFFFFF">
Upvotes: 0
Views: 106
Reputation: 1979
Ill suggets a way that will be generic:
Use a XML parser for the same.
This way is complex but will be generic to all ur such needs..
Upvotes: 0
Reputation: 520
You can use jQUery for this:
$( ".temporaryrevision" ).attr( "bgcolor", "#FFFFFF" );
Upvotes: 1
Reputation: 2952
String htmlString="<html>...<body class="temporaryrevision">..</body>...</html>";
String[] tempData=htmlString.split("<body class=/"temporaryrevision/"");
String data = tempData[0]+"bgcolor=/"#FFFFFF/""+tempData[1];
Upvotes: 2