-1

I have a HTML text as input, keyword as input and URL address as input also.

How should i find that keyword in the text and surround it with anchor element, putting the URL in the href attribute and the keyword in the InnerText part of the element?

Notice that the keyword can't be an attribute of some other element in the HTML text and also it can't be already inside an anchor (already within a link).

John Saunders
  • 160,644
  • 26
  • 247
  • 397
YanivHer
  • 123
  • 14
  • I have edited your title. Please see, "[Should questions include “tags” in their titles?](http://meta.stackexchange.com/questions/19190/)", where the consensus is "no, they should not". – John Saunders Jan 31 '13 at 13:24

1 Answers1

1

A tool commonly recommended for this is the Html Agility Pack. It will take malformed HTML and massage it into XHTML and then a traversable DOM, so is very useful for the code you find in the wild, as opposed to approaches like RegEx, which are destined to break.

There are some examples and the API documentation here:

http://html-agility-pack.net/api

Some useful links:

wp78de
  • 18,207
  • 7
  • 43
  • 71
Massimiliano Peluso
  • 26,379
  • 6
  • 61
  • 70