git.iko.soy/typeable/xml-conduit-writer
on master help sign in
2 files changed+45−3
since splitsnapshots
unifiedsplit
src/Text/XML/Writer.hs+42−3 stack.yaml+3
src/Text/XML/Writer.hs+42−3
@@ -1,4 +1,4 @@
1−{-# LANGUAGE OverloadedStrings, TypeSynonymInstances, FlexibleInstances #-}
1+{-# LANGUAGE OverloadedStrings, TypeSynonymInstances, FlexibleInstances, CPP #-}
22{-# OPTIONS_GHC -fno-warn-orphans #-} -- IsString for XML
33
44-- | Overcome XML insanity, node by node.
@@ -17,7 +17,11 @@
1717module Text.XML.Writer
1818 (
1919 -- * Documents
20− document, soap
20+ document
21+ , documentA
22+ , documentD
23+ , documentAD
24+ , soap
2125 , pprint
2226 -- * Elements
2327 , XML
@@ -36,7 +40,6 @@ module Text.XML.Writer
3640 ) where
3741
3842import Text.XML
39−import Control.Monad
4043import Control.Monad.Writer.Strict
4144import Data.Default ()
4245import qualified Data.DList as DL
@@ -47,6 +50,10 @@ import qualified Data.Text as T
4750import qualified Data.Text.Lazy.IO as TL
4851import Data.String (IsString(..))
4952
53+#if MIN_VERSION_mtl(2,3,0)
54+import Control.Monad
55+#endif
56+
5057-- | Node container to be rendered as children nodes.
5158type XML = Writer (DL.DList Node) ()
5259
@@ -59,6 +66,38 @@ document name children = Document { documentPrologue = Prologue def def def
5966 , documentEpilogue = def
6067 }
6168
69+
70+-- | Create a simple Document starting with a root element with attributes.
71+documentA :: Name -- ^ Root node name
72+ -> [(Name, Text)] -- ^ Attributes
73+ -> XML -- ^ Contents
74+ -> Document
75+documentA name attrs children = Document { documentPrologue = Prologue def def def
76+ , documentRoot = Element name (M.fromList attrs) (render children)
77+ , documentEpilogue = def
78+ }
79+
80+-- | Create a simple Document starting with a root element with a doctype.
81+documentD :: Name -- ^ Root node name
82+ -> Maybe Doctype -- ^ DOCTYPE
83+ -> XML -- ^ Contents
84+ -> Document
85+documentD name dt children = Document { documentPrologue = Prologue def dt def
86+ , documentRoot = Element name def (render children)
87+ , documentEpilogue = def
88+ }
89+
90+-- | Create a simple Document starting with a root element with attributes and doctype.
91+documentAD :: Name -- ^ Root node name
92+ -> [(Name, Text)] -- ^ Attributes
93+ -> Maybe Doctype -- ^ DOCTYPE
94+ -> XML -- ^ Contents
95+ -> Document
96+documentAD name attrs dt children = Document { documentPrologue = Prologue def dt def
97+ , documentRoot = Element name (M.fromList attrs) (render children)
98+ , documentEpilogue = def
99+ }
100+
62101-- | Render document using xml-conduit's pretty-printer.
63102pprint :: Document -> IO ()
64103pprint = TL.putStrLn . renderText def { rsPretty = True }
stack.yaml+3
@@ -2,3 +2,6 @@ resolver: lts-22.4
22
33packages:
44- .
5+
6+nix:
7+ packages: [zlib]