$xml_regex = '{ ^( (?: <(\w++) [^>]*+ (? (?1) # matched pair of tags | [^<>]++ # non-tag stuff | <\w[^>]*+/> # self-closing tag | # comment | # cdata block | <\?.*?\?> # processing instruction | # Entity declaration, etc. )*+ )$ }sx'; if (preg_match($xml_regex, $xml_string)) echo "block structure seems valid\n"; else echo "block structure seems invalid\n"; ----------------------------------------------------------------------------- Copyright 1997-2024 Jeffrey Friedl