split html content by tag [message #554519] |
Tue, 15 May 2012 02:00 |
Plymouth_Rock
Messages: 13 Registered: December 2008
|
Junior Member |
|
|
I need to modify the content of all html content to be sent as response from our server according to the tag. say for example, only text content inside a td or div tag will be modified. As per solution we have thought the content will be captured in the Filter of the server. Here, we will split the content against tag and modify the desired text, and then merge them again.
So, for example, if my content is,
.....
<tr>
<td valign="center">Claim Event Code </td>
<td><input type="text" class="field" name="EventCode"size="20"></td>
<td valign="center">
<SELECT name="pClaimStatus" >
<option value=""selected></option>
<option value="A">Notified</option>
<option value="B">Opened</option>
.....
then my desired output (may be an array) will be like this --
1. <tr>
2. <td valign="center">
3. Claim Event Code
4. </td>
5. <td>
6. <input type="text" class="field" name="EventCode"size="20">
7. </td>
8. <td valign="center">
9. <SELECT name="pClaimStatus" >
10. <option value=""selected>
11. </option>
12. <option value="A">
13. Notified
14. </option>. .
15. <option value="B">
16. Opened
17. </option>
so that now I can work upon item 3, 13, 16 and so on.
Is this method is ok? if so how could we split and get such array in java.
Thanks in Advance,
Plymouth_Rock
|
|
|
Re: split html content by tag [message #554521 is a reply to message #554519] |
Tue, 15 May 2012 02:16 |
|
Michel Cadot
Messages: 68732 Registered: March 2007 Location: Saint-Maur, France, https...
|
Senior Member Account Moderator |
|
|
Not a direct xml/html answer but could be something like:
SQL> with
2 data as (
3 select '<tr>
4 <td valign="center">Claim Event Code </td>
5 <td><input type="text" class="field" name="EventCode"size="20"></td>
6 <td valign="center">
7 <SELECT name="pClaimStatus" >
8 <option value=""selected></option>
9 <option value="A">Notified</option>
10 <option value="B">Opened</option>
11 .....' val from dual
12 ),
13 lines as ( select level line from dual connect by level <= 100 )
14 select trim(ltrim(rtrim(regexp_substr (val, '>[^<]*</', 1, line), '</'), '>')) res
15 from data, lines
16 where trim(ltrim(rtrim(regexp_substr (val, '>[^<]*</', 1, line), '</'), '>')) is not null
17 /
RES
-----------------------------------------------------------------------------------------------
Claim Event Code
Notified
Opened
3 rows selected.
Regards
Michel
|
|
|
Re: split html content by tag [message #554534 is a reply to message #554521] |
Tue, 15 May 2012 04:13 |
Plymouth_Rock
Messages: 13 Registered: December 2008
|
Junior Member |
|
|
Thanks Michel for the thought. But this is not fulfilling the requirement. The reason is I need the whole array of 17 elements as in the example. Then only I can recreate the html after specific modifications.
|
|
|
|
Re: split html content by tag [message #554537 is a reply to message #554536] |
Tue, 15 May 2012 04:38 |
Plymouth_Rock
Messages: 13 Registered: December 2008
|
Junior Member |
|
|
for some reason I cannot provide exact example here. but the given one is pretty workable, I believe. In the example I have just taken a small part of a whole html response, so obviously it will have start and end tag of html, body etc., all in right places.
now, say for some specific tags, I need to change the text; say I will append "#". Hence,
1. "Claim Event Code " will become "Claim Event Code #"
2. "Notified" will become "Notified#"
3. "Opened" will become "Opened#"
This modification can be possible if I have the whole array of that 17 elements (see 1st post, please) with me, and I would now be able to append all these elements and send as a complete html response.
|
|
|
|
|
|
Re: split html content by tag [message #554548 is a reply to message #554547] |
Tue, 15 May 2012 08:31 |
Plymouth_Rock
Messages: 13 Registered: December 2008
|
Junior Member |
|
|
sql soln is quite time consuming as there will be db connection and this process is required for each and every response from server.
I opted an approach. 1st I modify the response with an extra "#" (or could be any special character that can be used as separator) before "<"(tag start) and after ">"(tag end). so now code will look like --
#<tr>#
#<td valign="center">#Claim Event Code #</td>#
#<td>##<input type="text" class="field" name="EventCode"size="20">##</td>#
#<td valign="center">#
#<SELECT name="pClaimStatus" >#
#<option value=""selected>##</option>#
#<option value="A">#Notified#</option>#
#<option value="B">#Opened#</option>#
Now simple Java coding can be used to separate this into an array using "#". consecutive "#"es need to be ignored. so now I can scan the array, check any desired tag and opearte (and modify, too) the next element as I wish. Then I will recreate my response, just concatinating the array.
Using db connection may make the response slower. more over, tag wise opeartion may vary and managing them in sql, I feel, bit complex. But the query was good and I had learnt something new. Thanks Michel.
|
|
|