module Extra.HaXml where
import Text.PrettyPrint.HughesPJ
import Text.XML.HaXml
import Text.XML.HaXml.Pretty
showXML :: String -> CFilter -> Doc
showXML styleSheet = document . mkDocument styleSheet . cfilterToElem
mkTxt :: String -> CFilter
mkTxt = cdata
cfilterToElem :: CFilter -> Element
cfilterToElem f = case f (CString False "") of
[CElem e] -> xmlEscape stdXmlEscaper e
[] -> error "RSS produced no output"
_ -> error "RSS produced more than one output"
mkDocument :: String -> Element -> Document
mkDocument styleSheet elem =
let xmlDecl = XMLDecl "1.0" (Just (EncodingDecl "utf-8")) (Just True)
prolog = Prolog (Just xmlDecl) [] Nothing [PI ("xml-stylesheet","type=\"text/xsl\" href=\""++styleSheet++"\"")]
symTable = []
in
Document prolog [] elem []