Solved

Handeling <LI> from the database

Posted on 2004-04-15
12
302 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
 
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
What Should I Do With This Threat Intelligence?

Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

 
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

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

In this article, I will show you HOW TO: Suppress Configuration Issues and Warnings Alert displayed in Summary status for ESXi 6.5 after enabling SSH or ESXi Shell.
A safe way to clean winsxs folder from your windows server 2008 R2 editions
Internet Business Fax to Email Made Easy - With eFax Corporate (http://www.enterprise.efax.com), you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, fr…
This video gives you a great overview about bandwidth monitoring with SNMP and WMI with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're looking for how to monitor bandwidth using netflow or packet s…

762 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

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now