Routine For Stripping Off HTML Tags?
Mar 10, 2010
In my application, there's a module that displays a user's assignments. Sometimes these assignment descriptions are pretty long that's why I display up to 500 characters of the description. However, because I use an HTML editor in the app, if I blindly grab the first 500 characters, there's a good chance the description will look very funky due to missing HTML tags. So, I first need to strip off all the HTML tags, then grab the first 500 characters. Before I re-invent the wheel, I wanted to see if someone else has already tackled this issue and would be kind enough to share his/her code with me.
View 6 Replies
Similar Messages:
Mar 29, 2010
There are lots of questions on how to strip html tags, but not many on functions/methods to close them.
Here's the situation. I have a 500 character Message summary ( which includes html tags ), but I only want the first 100 characters. Problem is if I truncate the message, it could be in the middle of an html tag... which messes up stuff.
Assuming the html is something like this:
<div class="bd">"Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. <br/>
<br/>Some Dates: April 30 - May 2, 2010 <br/>
<p>Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. <em>Duis aute irure dolor in reprehenderit</em> in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum. <br/>
</p>
For more information about Lorem Ipsum doemdloe, visit: <br/>
<a href="http://www.somesite.com" title="Some Conference">Some text link</a><br/>
</div>
How would I take the first ~100 characters or so? ( Although, ideally that would be the first approximately 100 characters of "CONTENT" ( in between the html tags )
I'm assuming the best way to do this would be a recursive algorithm that keeps track of the html tags and appends any tags that would be truncated, but that may not be the best approach.
My first thoughts are using recursion to count nested tags, and when we reach 100 characters, look for the next "<" and then use recursion to write the closing html tags needed from there.
The reason for doing this is to make a short summary of existing articles without requiring the user to go back and provide summaries for all the articles. I want to keep the html formatting, if possible.
NOTE: ignore that the html isn't totally semantic. This is what I have to deal with from my WYSIWYG.
EDIT:
I added a potential solution ( that seems to work ) I figure others will run into this problem as well. I'm not sure it's the best... and it's probably not totally robust ( in fact, I know it isn't ),
View 4 Replies
Jan 6, 2011
I want to implement readmore/less feature. i.e I will be having html content and I am going to show first few characters from that content and there will be a read more link in front of it. I am currently using this code :
var txtToHide= input.substring(length);
var textToShow= input.substring(0, length);
var html = textToShow+ '<span class="readmore"> … </span>'
+ ('<span class="readmore">' + txtToHide+ '</span>');
html = html + '<a id="read-more" title="More" href="#">More</a>';
Above input is the input string and length is the length of string to be displayed initially. There is an issue with this code, suppose if I want to strip 20 characters from this string:
"Hello <a href='#'>test</a> output", the html tags are coming between and it will mess up the page if strip it partially. What I want here is that if html tags are falling between the range it should cover the full tag i.e I need the output here to be "Hello <a href='#'>test</a>" . How can I do this?
View 5 Replies
Mar 8, 2011
I want regex operation for removing style tags,css,scripts and html tags from html to plain text in asp.net c#...
View 1 Replies
Mar 27, 2010
i'm doing ajax website using PostWebRequest() function, when i call any .aspx page to the target html element the output is coming fine in IE but in FF(FireFox) is coming in html format(html tags) IE output : [URL] FF output : [URL]
javascript functions :
function PostWebRequest(postPage, HTMLTarget, parameter) {
displayElement = $get(HTMLTarget);
displayElement.innerHTML = "<div style='text-align:center;'><br /><br /><br /><br /><br /><img src='images/ajax-loader.gif' algin='center' /></div>";
var wRequest = new Sys.Net.WebRequest();
wRequest.set_url(postPage);
wRequest.set_httpVerb("POST");
var body = parameter;
wRequest.set_body(body);
wRequest.get_headers()["Content-Length"] = body.length;
wRequest.add_completed(onWebRequestCompleted);
wRequest.invoke();
}
function onWebRequestCompleted(executor, eventArgs) {
if (executor.get_responseAvailable()) {
if (document.all) {
displayElement.innerHTML = executor.get_responseData();
}
else {
displayElement.textContent = executor.get_responseData();
}
}
else {
if (executor.get_timeOut()) {
alert("Timed Out");
}
else {
if (executor.get_aborted())
alert("Aborted");
}
}
}
View 1 Replies
Aug 27, 2010
I have implemented a custom ModelMetadataProvider so that I can decorate my view models with some custom attributes and everything was working fine until I made use of a Partial View. The following code in my view works fine: -
<%: Html.DisplayFor(x => x.Results) %>
Results is a List which renders a custom display template and is also decorated with a custom attribute. Using breakpoints, after the above line and prior to the code within the custom display template, the overridden CreateMetadata method in my custom ModelMetadataProvider is invoked. If I look at the attributes collection parameter I can see that it does contain my custom attribute thus everything working as expected. However, if I replace the above with the following line of code in my view then it breaks: -
<% Html.RenderPartial("ApplicationSearchResults", Model.Results, new ViewDataDictionary()); %>
All the Partial View contains is: -
<%: Html.DisplayFor(x => x) %>
Again using breakpoints, after the above line and prior to the code within the custom display template, the overridden CreateMetadata method in my custom ModelMetadataProvider is invoked. But this time if I look at the attributes collection parameter my custom attribute is not there.
View 4 Replies
Oct 24, 2010
I have to break a HTML content string in to multiple lines. And each line should have some fixed characters, 50 or 60 Also I don't want to break the word..or html tags...
ex : <p>Email: <a href="mailto:someone@gmail.com">someone@gmail.com</a></p>
<p><em>"Text goes <font color=red>Hello world</font> Text goes here and Text goes here Text goes here 1976."</em> </p>
How can I acheive this in C#?
View 1 Replies
Jan 31, 2011
How can I remove all html tags and script tags? consider also short tags like unclosed tags
<script>blah...</script>
<body> aaa<b>bbb</body>
This should return aaa bbb.
notice that all the contents inside the script tag is ignored.
View 3 Replies
Jun 27, 2010
how can i use basic html tags(h1,h2 and <p>) in code behind.
View 4 Replies
Mar 8, 2011
For the last time I've been using EWS MAPI to connect to Exchange Server. After this is done I access my mails and firstly display their body (which contains a LOT HTML-tags) in a gridview. After you select a record of that gridview the body is shown in a freetextbox.
View 3 Replies
Sep 2, 2010
I have a text area in my ASP.NET web application that is used to enter html code. Now there is also an button control, which upon clicking should retrieve just the text placed between certain html tags in the text box. For example:
1) User types html code including tags etc. and clicks the OK button
2) In my code the text from the text area is retrieved and only the part between a <p></p> tag should be saved to a string object.
I can obviously get the text from the text area and attach it to a string object but I am not able to work out how to just get text within a certain html tag like <p></p>
View 2 Replies
Feb 12, 2010
I want to get some data from html tags in a web page. For example I have a web site that's got [URL], this is text which I want to split. I want to first URL, First text thats between in first span tags and last text that's between the last span tags.
How can I do this with C# ASP.NET 2.0 (not 3.5)?
<a class="tablolinkmetin" target="_blank" href="http://www.iwantthisurl.com/test/2010/subat/12022010_adli_krrnme.htm">
<img alt=icon src="images/icon/ok.gif" border=0 width="7" height="8">
<span class=tablolink>
<span class="genelgeler_mbaslik">I want this text.</span>
</span>
<span class="tablolinkaltyazi"><br>and i want here</span>
</a>
<img src="images/icon/cizgi.png" width="260" height="1"><br>
View 2 Replies
May 8, 2010
I am getting unlikely html tags for hidden fields in my website when redirecting to the page. I do not get it all the time but I am getting it frequently. e.g.: I was support to get
<input type="hidden" name="__EVENTTARGET"
id="__EVENTTARGET" value="" />
but I am getting something like
tyinput type="hidden" name="__EVENTTARGET"
id="__EVENTTARGET" value="" />
and this error is displayed in top of the page.
View 3 Replies
Jun 19, 2010
I am trying to build a white list. I am using html agility pack to remove all tags I do not allow. however this only gets ride of these type of script tags
[Code]....
View 2 Replies
Jun 9, 2010
Is there anyway to access HTML tags using C#? For example, I am able to change the text of the ASP Label, but not the HTML label in the below example.
[Code]....
View 3 Replies
Mar 25, 2011
In may page, i am assigning DataTable to a GridView as follows:
GridView1.DataSource = GetDataTable();
GridView1.DataBind();
Now,the definition of GetDataTable is as follows:
DataTable abcd = new DataTable();
DataRow dr;
abcd.Columns.Add(new DataColumn("Column1"));
abcd.Columns.Add(new DataCoumn("Column2"));
dr=abcd.NewRow();
dr["Column1"]="My Name";
dr["Column2"]="<p>My Address Line1</p><p>My Address Line2</p>";
abcd.AddRow(dr);
return(abcd);
dont bother about code syntax or functions, I just dont have actual code right now.Its on the similar lines...
My question is, when i see GridView, It prints <p></p> in Column2 as it is.. it doesnt consider those tags as HTML tags...
I want DataColumn to consider those tags as HTML, so that my address gets printed on two different lines but in same column.
If you guys have any other way to work around... just the thing is that I must assign DataTable to GridView.
View 2 Replies
Mar 6, 2011
<asp:ContentPlaceHolder id="ContentPlaceHolder1" runat="server">
<script src="http://ajax.aspnetcdn.com/ajax/jQuery/JScript.js" type="text/javascript"></script>
<script src="http://ajax.aspnetcdn.com/ajax/jQuery/fns.js" type="text/javascript"></script> [code]....
View 2 Replies
Dec 28, 2010
So I'm writing an app that lets the user select a folder, it gets all the .aspx files in that folder, and lets the users check off which ones they want to add HTML ID's to.
Then they click start, and this runs
private void btnStart_Click(object sender, EventArgs e)
{
for (int i = 0; i < listFiles.CheckedItems.Count; i++)
{
}
}
It loops through all the selected file names. How do I open each of these .aspx files in the background, and go through them and add the id="thisItemId"
View 2 Replies
Apr 14, 2010
I have a SharePoint web part that I wrote in C# which is used to display SQL Server data based on user selections. I pull the data with a DataReader, fill a DataSet with it, and set that DataSet as the DataSource in a GridView and add that control to my page:
GridView outputGrid = new GridView();
outputGrid.CssClass = "OutputGrid";
outputGrid.DataSource = flipped_ds1;
outputGrid.RowDataBound += outputGrid_RowDataBound;
outputGrid.DataBind();
Controls.Add(outputGrid);
This gives me a simple HTML table with a declared CSS class and that's about it. The only problem I'm facing is that line breaks in the data fields are not being rendered at all. I'm simply getting a block of text that ignores the breaks that are present in the database when it's rendered to HTML. In stepping through my code, I see that the newlines are coming in as text in the form of "". I tried a regex:
[code]....
View 3 Replies
Jan 19, 2010
In my database MYDB I have a table called MYTABLE and I have a column called Description. I am saving a long description in there with multiple HTML tags.
How can i return the values and not include all the HTML tags?
Is this even possible? What will be the best way of doing this? In the SQL statement or in code behind? And how will I do it?
View 3 Replies
Jun 16, 2010
I have to set image on the basis of fields value coming from db. I want it to achieve via. tags <%# %>. For example i have collection binded with grid. It has a Field called Online which is boolean. So if the value of Online is true then the green.png will be set as path of asp:image control else grey.png will be the path of the asp: image control.
View 1 Replies
Dec 6, 2010
develop one html website, but in this page i want to contact us page, in this page i fill all details and press send button , all fields data must be send unique mail( same like contact page .html )
View 3 Replies
Jan 4, 2011
Just wondering what the best approach is to labelling ID's (thats html id's) in .net.
For instance I may have a user control that is embedded in a page more than once. If I have a standard html div in the control with id="my-user-control", then it will duplicated when the page is built.
So what is the best approach for styling your html within user controls, master pages and .net in general?
View 4 Replies
Feb 28, 2011
I've looked around and can't find a solution for this and it's driving me mad.I've got a basic MVC2 app (C#) and am trying to display text from a database with the line breaks included. I've used the following:
<p><label>Description:</label>
<span class="fieldBlock"><%: Model.Description.Replace(System.Environment.NewLine, "<br />") %></span>
</p>
This is adding the tags to the returned string as I'd expect but when the page renders it actually displays the tag as is instead of rendering the newline. ie. the text seen by the user in the browser is:"Quisque justo erat, iaculis sit amet aliquam eu, porttitor in mauris.<br /><br />Maecenas nisi velit, euismod at molestie vitae, malesuada id turpis. Mauris diam nisl, pretium id molestie nec, posuere posuere neque.<br /><br />Cras sed lectus nisl."
View 1 Replies
Jul 11, 2010
How to display HTML Tags in my asp.net page?
Example: I need to load the following text from DB and display it in my page.
<p> </p> <h1 style="text-align: center"><span style="background-color: yellow">Hello World</span></h1>
I have assigned it to a placeholder but it display as is not as tags.
View 8 Replies