module Exercise04 where import Data.Char {-WETT-} xmlLight :: String -> Bool xmlLight xml = null $ validsub (xml ++ "") "" validsub :: String -> String -> String validsub ('<' : '/' : xml) tag = removeTag (tag == parseTag xml) xml validsub (x : xml) tag = case x of '<' -> removeTag (parseTag xml /= ">") xml `validsub` parseTag xml `validsub` tag '>' -> ">" _ -> validsub xml tag validsub _ _ = ">" removeTag :: Bool -> String -> String removeTag cond xml = if cond then tail $ dropWhile (/= '>') xml else ">" parseTag :: String -> String parseTag (x : xml) = case x of '/' -> ">" '<' -> ">" ' ' -> if head (dropWhile isSpace xml ++ "<") == '>' then "" else ">" '>' -> "" _ -> if parseTag xml /= ">" then x : parseTag xml else ">" parseTag _ = ">" {-TTEW-}