From 75ae0f91a95dc4158d1611a6a6fa57d4dec16fd1 Mon Sep 17 00:00:00 2001 From: Christopher Bruce Billheimer Date: Fri, 14 Jul 2023 10:30:39 +0000 Subject: [PATCH] Add documentD and documentAD functions to Writer.hs --- src/Text/XML/Writer.hs | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/src/Text/XML/Writer.hs b/src/Text/XML/Writer.hs index f9b0034..65e8f66 100644 --- a/src/Text/XML/Writer.hs +++ b/src/Text/XML/Writer.hs @@ -68,6 +68,27 @@ documentA name attrs children = Document { documentPrologue = Prologue def def d , documentEpilogue = def } +-- | Create a simple Document starting with a root element with a doctype. +documentD :: Name -- ^ Root node name + -> Maybe Doctype -- ^ DOCTYPE + -> XML -- ^ Contents + -> Document +documentD name dt children = Document { documentPrologue = Prologue def dt def + , documentRoot = Element name def (render children) + , documentEpilogue = def + } + +-- | Create a simple Document starting with a root element with attributes and doctype. +documentAD :: Name -- ^ Root node name + -> [(Name, Text)] -- ^ Attributes + -> Maybe Doctype -- ^ DOCTYPE + -> XML -- ^ Contents + -> Document +documentAD name attrs dt children = Document { documentPrologue = Prologue def dt def + , documentRoot = Element name (M.fromList attrs) (render children) + , documentEpilogue = def + } + -- | Render document using xml-conduit's pretty-printer. pprint :: Document -> IO () pprint = TL.putStrLn . renderText def { rsPretty = True }