Solved

Handeling <LI> from the database

Posted on 2004-04-15
12
305 Views
Last Modified: 2010-04-01
Hello Expert,
I am getting the body of a story from the database and it looks like this

This is a great story
<li> Testing this story</li>
<li> Testing Two</li>
<li> Testing three </li>

I would like to change everything that is in the <li>Testing this story </li> to dipsplay in my text are as
This is a great story
• Testing this story
• Testing Two
• Testing three
Is there anyway to do this?
Thanks
0
Comment
Question by:jvoros1
  • 4
  • 3
  • 3
  • +1
12 Comments
 
LVL 9

Expert Comment

by:Nick_72
ID: 10834165
I'm not sure I understand...you have this text in a variable, and if you print out that variable in your html, you don't get it formatted?
Can you show how your code looks now?
0
 

Author Comment

by:jvoros1
ID: 10834295
I hope this helps and in the body this is what is stored
This is a great story
<li> Testing this story</li>
<li> Testing Two</li>
<li> Testing three </li>
and i want it to look like
This is a great story
• Testing this story
• Testing Two
• Testing three
Object[] search_results = (Object[])request.getAttribute("search_results");
                  
                  for (int x = 0; x < search_results.length; x++)                            
                  {              
                        HashMap search_result = (HashMap)search_results[x];
                        
                                 String EventID = (String) search_result.get("EventID");
                              String Body =  (String) search_result.get("Body");
                              String Title = URLEncoder.encode(tmpTitle);
                                                 }
<table>
  <tr>
    <td> <textarea rows="19" name="Body" cols="54"><%=Body%></textarea></td>
  </tr>
</table>
Thanks
0
 
LVL 7

Expert Comment

by:searlas
ID: 10834523
A textarea cannot display rendered HTML.  No doubt someone will point you at a few options out there that look like they do, but basically they hide the textarea and use iframes and massive amounts of javascript instead.  for instance:

http://www.interactivetools.com/products/htmlarea/
0
Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 
LVL 9

Expert Comment

by:Nick_72
ID: 10834529
oh...textarea...I missed that part :)

well, I'm not sure if that is possible. I know another thing that is possible though and could be equally as good, or better. That depends on if the user should be able to edit that text or not. With this example, he/she is not able to do that, but if it's only for presentation - that would suite just fine.

Check this example. It makes a 'fake' textarea which looks as an original, but which allows you to use ordinary html in it:

<HTML>
<head>
<STYLE>
.textAREA {border:3px ridge #dddddd;height:200;width:300;overflow-y:scroll;
border-right:3px double #bbbbbb; border-bottom:3px double #bbbbbb;}

.hiliteON {color:white;background-color:navy;font-family:arial;font-size:10pt}
.hiliteOFF {color:black;background-color:white;font-family:arial;font-size:10pt}
</STYLE>

</HEAD>
<BODY>
<div class="textAREA" style="position:absolute;left:165;top:115">
<li>test 1</li>
<li>test 2</li>
</div>
</BODY>
</HTML>

Hope it helps,

/Nick
0
 
LVL 7

Assisted Solution

by:searlas
searlas earned 125 total points
ID: 10834543
So... to get your 'body' displayed as you want, you shouldn't use a text area at all:
<table>
  <tr>
    <td> <textarea rows="19" name="Body" cols="54"><%=Body%></textarea></td>
  </tr>
</table>

becomes:
<%=Body%>
0
 
LVL 19

Expert Comment

by:Kuldeepchaturvedi
ID: 10834627
try


<td> <textarea rows="19" name="Body" DATAFORMATS="html" cols="54"><%=Body%></textarea></td>
0
 
LVL 19

Expert Comment

by:Kuldeepchaturvedi
ID: 10834643
ooops

it should be

<td> <textarea rows="19" name="Body" DATAFORMATAS="html" cols="54"><%=Body%></textarea></td>


http://msdn.microsoft.com/workshop/author/dhtml/reference/properties/dataformatas_1.asp
0
 

Author Comment

by:jvoros1
ID: 10834656
The user has to be able to edit the text cause this is an update to what they added. SO i am not sure if it will work cause i have more then just that one row i have many rows in my table. And this page is an include in another page? Do you know maybe how i could use a hashcode to do this or a stringtokenizer is that possible some how?
0
 
LVL 19

Assisted Solution

by:Kuldeepchaturvedi
Kuldeepchaturvedi earned 125 total points
ID: 10834739
If all you want to do is to strip off the <LI> and </LI> tag than you can use string tokenizer to separate them..
Hashtable ht=new Hashtable();
int count =0;
StringTokenizer st  = new StringTokenizer(body,"<li>");
while(st.hasMoreElements())
{
String token = st.nextToken();
token = token.subString(0,token.indexOf("</li>");
//put this token where ever you want to..
hastable.put(count,token);
count++;
}

Here I am assuming that all the li tags are in small case....
0
 

Author Comment

by:jvoros1
ID: 10834750
I tried <td> <textarea rows="19" name="Body" DATAFORMATAS="html" cols="54"><%=Body%></textarea></td> too and it still comes up as
<li>       One</li>
 <li>       Two </li>
 <li>       three</li>
:(

0
 
LVL 9

Accepted Solution

by:
Nick_72 earned 250 total points
ID: 10834757
I don't know how to display that 'dot' in a textarea, but if you can think of showing an asterisk or some other character instead, you could always use the replaceAll() method:

String newBody = Body.replaceAll("<li>", "* ");
newBody = newBody.replaceAll("</li>", "");

/Nick

0
 
LVL 9

Expert Comment

by:Nick_72
ID: 10834846
:)

actually, if you want a new line after every </li> you might want do like this instead:

newBody = newBody.replaceAll("</li>", "\n");

/Nick
0

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
netstat -a in AIX unix 8 48
how to hide hide popup page refresh second time? 10 145
login form jsp example 2 39
spring maven example issues 3 13
This article shows the method of using the Resultant Set of Policy Tool to locate Group Policy that applies a particular setting.
Smart phones, smart watches, Bluetooth-connected devices—the IoT is all around us. In this article, we take a look at the security implications of our highly connected world.
The Email Laundry PDF encryption service allows companies to send confidential encrypted  emails to anybody. The PDF document can also contain attachments that are embedded in the encrypted PDF. The password is randomly generated by The Email Laundr…
In an interesting question (https://www.experts-exchange.com/questions/29008360/) here at Experts Exchange, a member asked how to split a single image into multiple images. The primary usage for this is to place many photographs on a flatbed scanner…

821 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question