Given a string code representing a code snippet, return true if it is a valid tag snippet, or false otherwise.
A code snippet is considered valid if all of the following conditions are met:
The entire code must be enclosed by a single valid root tag: <TAG_NAME>TAG_CONTENT</TAG_NAME>.
A valid TAG_NAME consists only of uppercase English letters, and its length must be in the range
A start tag is formatted as <TAG_NAME>.
An end tag is formatted as </TAG_NAME>, where the TAG_NAME matches the corresponding start tag.
A valid TAG_CONTENT may contain valid closed tags, cdata, or any characters, provided that start tags and end tags are properly paired and nested.
A cdata section begins with <![CDATA[ and ends at the first subsequent occurrence of ]]>. The enclosed text, CDATA_CONTENT, is treated as raw text and is not parsed for tags.
Tags must be correctly matched and nested. A tag cannot be closed if there are open child tags inside it.
Unmatched '<' characters, unmatched <![CDATA[, or unmatched ]]> are strictly invalid.
Constraints:
code.length
code consists of English letters, digits, '<', '>', '/', '!', '[', ']', '.', and ' '.
Given a string code representing a code snippet, return true if it is a valid tag snippet, or false otherwise.
A code snippet is considered valid if all of the following conditions are met:
The entire code must be enclosed by a single valid root tag: <TAG_NAME>TAG_CONTENT</TAG_NAME>.
A valid TAG_NAME consists only of uppercase English letters, and its length must be in the range
A start tag is formatted as <TAG_NAME>.
An end tag is formatted as </TAG_NAME>, where the TAG_NAME matches the corresponding start tag.
A valid TAG_CONTENT may contain valid closed tags, cdata, or any characters, provided that start tags and end tags are properly paired and nested.
A cdata section begins with <![CDATA[ and ends at the first subsequent occurrence of ]]>. The enclosed text, CDATA_CONTENT, is treated as raw text and is not parsed for tags.
Tags must be correctly matched and nested. A tag cannot be closed if there are open child tags inside it.
Unmatched '<' characters, unmatched <![CDATA[, or unmatched ]]> are strictly invalid.
Constraints:
code.length
code consists of English letters, digits, '<', '>', '/', '!', '[', ']', '.', and ' '.