Posted on 2005-04-26
I have quite a complex problem......
Our site content is generated dynamically from a database. We also have a page of a glossary of terms used on the site. I would like to parse the dynamic content and check if the terms are contained in it, and if so link to it....
Database content: "This is some text on our site"
Glossary term: "our site"
The result would be "This is some text on <a href="/glossary.aspx?term=our site">our site</a>"
Now I can do this quite easily by looping through the glossary terms (DataTable) and then simply checking for a match. If there is a match I simply replace the original text with that of the link.
THE PROBLEM with this method is that it only works for plain text and not for HTML which I need it to. What happens for example if the text is already contained in a link, this would create a link within a link. In addition there would be certain tags I would not want to make this happen to. For example if the term was already contained within an <h1>
Therefore I need to find a way of doing this where I can exclude terms which are already contained within tags that I specifiy (e.g. <a>, <h1> etc...)
This is where I get lost......
I will give many many points for a solution...