I have SaxElement from Sax parser in HaXml. What is the best way to print valid XML encoded text back from SaxElement elements? Especially I am interesting in printing XML-encoded text from SaxReference. Unfortunately SaxElement is not a member of Show type class and show of internal types like Reference does not return XML-encoded text. For example "&" is printed back by show as RefEntity "amp".
I tried to make SaxElement member of Show. But it is not complete and looks ugly. Is there a better way?
instance Show(SaxElement) where
show (SaxDocTypeDecl decl) = "<!-- TODO: doctype -->"
show (SaxProcessingInstruction pi) = "<!-- TODO: processing instruction -->"
show (SaxComment s) = "<!--" ++ s ++ "-->"
show (SaxElementOpen n attrs) = "<" ++ n ++ ">" -- TODO: attributes
show (SaxElementClose n) = "</" ++ n ++ ">"
show (SaxElementTag n attrs) = "<" ++ n ++ "/>" -- TODO: attributes
show (SaxCharData cd) = cd -- TODO: encode?
show (SaxReference r) = show(r) -- TODO: not encoded!
No comments:
Post a Comment