Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / ASP.NET / General / July 2007

Tip: Looking for answers? Try searching our database.

Search and Replace while ignoring HTML formatting?

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Josiwe - 24 Jul 2007 20:10 GMT
I have a search program that returns an HTML string which I display to
the user. I want to highlight the search terms. However a simple
search and replace on the HTML causes problems.

If the user searches on Georgia and I get back this:
<div style="font-name:Arial">Georgia, Alabama, and Louisiana</div>

It works fine:
<div style="font-name:Arial"><span style="background-
color:yellow;">Georgia</span>, Alabama, and Louisiana</div>

However if the HTML that comes back is this:
<div style="font-name:Georgia">Georgia, Alabama, and Louisiana</div>

I get a serious problem which breaks the formatting and looks
terrible:
<div style="font-name:<span style="background-color:yellow;">Georgia</
span>"><span style="background-color:yellow;">Georgia</span>, Alabama,
and Louisiana</div>

The HTML I'm getting back is quite complex, with nested spans, style
tags, etc. I'm stuck for how to solve this problem - is there a
regular expression I can use to match chunks of non-formatting text to
replace? I have neither the time nor the resources to write a full
blown html tokenizer.
Brandon Gano - 24 Jul 2007 20:17 GMT
You will probably want to use XHTML instead of HTML and use an XML parser to
do the work. You should be able to loop through text nodes and apply the
search/replace there.

>I have a search program that returns an HTML string which I display to
> the user. I want to highlight the search terms. However a simple
[quoted text clipped - 21 lines]
> replace? I have neither the time nor the resources to write a full
> blown html tokenizer.

Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.