{-% DrIFT (Automatic class derivations for Haskell) %-} {-% version 1.8 for Strafunski %-} -- | Strings representing XML content. -- -- CVS: $Id: XmlString.ds,v 1.2 2003/06/01 21:01:31 thor Exp $ -- -- Copyright (C) 2003 Tom Moertel -- Licensed under the terms of the GNU General Public License. -- See the LICENSE file in the project distribution for details. module XmlString where import DataGenerics import Data.Dynamic data XmlString = XSMixed String | XSCdata String | XSRun [XmlString] deriving (Eq, Read, Show) xsToXml :: XmlString -> String xsToXml = flip xsToXmlS "" xsToXmlS :: XmlString -> String -> String xsToXmlS (XSCdata s) = (escapeEntities s ++) xsToXmlS (XSMixed s) = (s ++) xsToXmlS (XSRun ss) = foldr (.) id (map xsToXmlS ss) xsToString :: XmlString -> String xsToString = flip xsToStringS "" xsToStringS :: XmlString -> String -> String xsToStringS (XSMixed s) = (s ++) xsToStringS (XSCdata s) = (s ++) xsToStringS (XSRun ss) = foldr (.) id (map xsToStringS ss) xsToAttrVal :: XmlString -> String xsToAttrVal = xsToXml {- no such thing as mixed attr values so we treat all as cdata xsToAttrValS :: XmlString -> String -> String xsToAttrValS (XSCdata s) = (escapeEntities s ++) xsToAttrValS (XSMixed s) = (escapeEntities s ++) xsToAttrValS (XSRun ss) = foldr (.) id (map xsToAttrValS ss) -} escapeEntities :: String -> String escapeEntities = concatMap quote where quote '&' = "&" quote '<' = "<" quote x = [x] {-* Generated by DrIFT-Strafunksi 1.8 : Look, but Don't Touch. *-} _tc_XmlStringTc = mkTyCon "XmlString" instance Typeable XmlString where typeOf x = mkAppTy _tc_XmlStringTc [ ] -- Imported from other files :- {-% DrIFT (Automatic class derivations for Haskell) %-} {-% version 1.8 for Strafunski %-} {-* Generated by DrIFT-Strafunksi 1.8 : Look, but Don't Touch. *-} instance Data XmlString where gfoldl f z (XSMixed aa) = z XSMixed `f` aa gfoldl f z (XSCdata aa) = z XSCdata `f` aa gfoldl f z (XSRun aa) = z XSRun `f` aa gunfold f z c | conString c == "XSMixed" = f (z XSMixed) gunfold f z c | conString c == "XSCdata" = f (z XSCdata) gunfold f z c | conString c == "XSRun" = f (z XSRun) conOf (XSMixed aa) = Constr{ conString = "XSMixed" } conOf (XSCdata aa) = Constr{ conString = "XSCdata" } conOf (XSRun aa) = Constr{ conString = "XSRun" } consOf _ = [ Constr{ conString = "XSMixed" } , Constr{ conString = "XSCdata" } , Constr{ conString = "XSRun" } ] -- Imported from other files :-