Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to check if string has a correct html syntax

Tags:

I would like to check if a given string has a correct html syntax. I don't know which html elements should be inside, the only one thing I know is that string should be a correct html expression.

Anyone has an idea how to check it in C#?

like image 985
ravenik Avatar asked Dec 15 '11 11:12

ravenik


People also ask

How do I check if a string contains HTML?

test. bind(/(<([^>]+)>)/i); It will basically return true for strings containing a < followed by ANYTHING followed by > .

How will you check if a HTML code is a valid HTML code?

The W3C MarkUp Validator: This looks at the (X)HTML doctype you are using for the document you give it to check, and then checks your markup accordingly. This is the one we recommend if you are using an HTML4 or XHTML1. x doctype. It does validate HTML5, but validator.nu is arguably more up to date.

How do you check string is HTML or not in JavaScript?

test with "<p>fizz buzz</p>" to check if "<p>fizz buzz</p>" is a JavaScript string. We use <\/?[a-z][\s\S]*> to check for any tags in the string to check if it has any HTML markup.


1 Answers

You can use Html Agility Pack : http://html-agility-pack.net/?z=codeplex

string html = "<span>Hello world</sspan>";  HtmlDocument doc = new HtmlDocument(); doc.LoadHtml(html);  if (doc.ParseErrors.Count() > 0) {    //Invalid HTML } 
like image 72
Romain Meresse Avatar answered Oct 10 '22 09:10

Romain Meresse