HTML Validation
- 3 minutes to read
The ASPxHtmlEditor automatically performs the validation of HTML code contained in an HTML View. This editor can remove all potentially harmful code such as unknown tags and attributes, script elements, client-side event handlers, URLs with script content, etc. The resulting HTML code is always safe, valid, and compliant with the specified document type (via the HtmlEditorHtmlEditingSettings.AllowedDocumentType property): XHTML 1.0 Transitional, HTML5, or both.
Automatic validation also helps to keep HTML code valid by correcting invalid tag hierarchies and changing invalid attribute values.
Additionally, you can use the ASPxHtmlEditor.CorrectHtml method to process any required HTML code to make it valid.
The main actions performed during validation are listed below:
- Converting all tag names to lower case;
- Correcting invalid tag overlapping;
- Correcting invalid tag nesting;
- Correcting invalid attribute values;
- Correcting invalid comment values.
- Removing unknown tags;
- Removing forbidden elements (asp.net directives, invalid processing instructions, etc.)
- Removing unknown attributes;
- Removing non-required attributes with empty values;
- Removing the closing tag if it is forbidden by the element’s content model;
- Removing attributes that are invalid for the current element kind;
Optionally removing tags and attributes of the following types:
- SCRIPT elements, client-side event handlers and HREF attributes with script content (if the HtmlEditorHtmlEditingSettings.AllowScripts property is set to false);
- IFRAME elements (if the HtmlEditorHtmlEditingSettings.AllowIFrames property is set to false);
- AUDIO and VIDEO elements (if the HtmlEditorHtmlEditingSettings.AllowHTML5MediaElements property is set to false);
- OBJECT and EMBED elements (if the HtmlEditorHtmlEditingSettings.AllowObjectAndEmbedElements property is set to false);
- IFRAMES elements containing a link to YouTube video (if the HtmlEditorHtmlEditingSettings.AllowYouTubeVideoIFrames property is set to false);
- all form elements such as FORM, INPUT and SELECT (if the HtmlEditorHtmlEditingSettings.AllowFormElements property is set to false);
- style attributes (if the HtmlEditorHtmlEditingSettings.AllowStyleAttributes property is set to false);
- ID attributes (if the HtmlEditorHtmlEditingSettings.AllowIdAttributes property is set to false);
- Closing the element within its start tag if the element content model is empty;
- Inserting the required attributes that have been omitted, using their default values;
- Encoding ampersands within the attribute value;
- Validating entity references and removing invalid ones;
- Replacing by-code entity references with their by-name equivalents, if possible;
- Deprecated elements (such as u, s, strike, font, center) found within the editor’s HTML markup should be replaced with their valid variants (if the HtmlEditorHtmlEditingSettings.UpdateDeprecatedElements property is set to true);
- Convert the b and i elements into the strong and em elements respectively (if the HtmlEditorHtmlEditingSettings.UpdateBoldItalic property is set to true).
For more information about editor parameters that allow you to control validation settings, see the HTML validation parameters topic.