-1

In my MVC solution, I have an HTML string and want to search for comment nodes and replace them based on their content.

How can I do this?

Thank you.

EDIT: The language is C#. The HTML string is e.g. "<div id='id1'>blahblah</div><!-- comment1 count='10' length='200' --><p>show real comment content before this paragraph.</p>". I need to get the comment block and then generate real content based on the count and length attributes.

Ben Blank
  • 54,908
  • 28
  • 127
  • 156
Jason Li
  • 1,194
  • 2
  • 11
  • 17
  • What is "search comment nodes" and what is "do replacement?" As it stands, your question is almost equivalent to "hey I want to do something" -- it lacks useful information required to help us help you. – cdhowie Jan 14 '11 at 03:47
  • Please post some more information Jason. What language are you performing the parsing in? Javascript? – Caps Jan 14 '11 at 03:48
  • Sorry for the not-clear post. For now what I do is to treat it as regular string and search " – Jason Li Jan 18 '11 at 18:12
  • Are you trying to do a template engine ? – HoLyVieR Jan 18 '11 at 18:31
  • This sounds like something you can do with a regex find and replace in visual studio. – P.Brian.Mackey Jan 18 '11 at 19:01
  • @HoLyVieR: I think yes, this is what I want. I was thinking maybe I could borrow someting from XmlDocument to search particular node and replace content. If we already have one somewhere on internet, that would be the best ;) – Jason Li Jan 18 '11 at 19:08
  • @JasonLi You can take a look at these question : http://stackoverflow.com/questions/1518954/c-template-engine OR http://stackoverflow.com/questions/733378/whats-a-good-way-of-doing-string-templating-in-net That should be a good start for what you want to do. – HoLyVieR Jan 18 '11 at 19:30

1 Answers1

1

Because of the complexity of HTML you should really use a rich library to help you.

I highly recommend HTMLAgility, you could then follow the advice from this post to work towards achieving your goal.

Community
  • 1
  • 1
shenku
  • 11,969
  • 12
  • 64
  • 118