@@ -4,6 +4,7 @@ module Text.XML.DOM.Parser.FromDom
44 , proxyFromDom
55 -- * Explicit methods for convenience
66 , elementFromDom
7+ , unionFromDom
78 , textFromDom
89 , stringFromDom
910 , charFromDom
@@ -20,6 +21,7 @@ module Text.XML.DOM.Parser.FromDom
2021import Control.Applicative
2122import Control.Lens
2223import Data.Fixed
24+import Data.OpenUnion
2325import Data.Scientific
2426import Data.Text as T hiding (empty)
2527import Data.Typeable
@@ -27,6 +29,7 @@ import Data.Void
2729import Text.XML
2830import Text.XML.DOM.Parser.Content
2931import Text.XML.DOM.Parser.Types
32+import TypeFun.Data.List hiding (Union)
3033
3134proxyFromDom
3235 :: forall proxy m a
@@ -113,6 +116,23 @@ instance FromDom Bool where
113116boolFromDom :: (Monad m) => DomParserT Identity m Bool
114117boolFromDom = parseContent readBool
115118
119+instance FromDom (Union '[]) where
120+ fromDom = empty
121+
122+instance
123+ ( Typeable a, FromDom a, FromDom (Union as)
124+ , SubList as (a ': as) )
125+ => FromDom (Union (a ': as)) where
126+ -- fromDom :: forall m. (DomParserMonad m) => m a
127+ fromDom = (liftUnion <$> (proxyFromDom (Proxy :: Proxy a)))
128+ <|> (reUnion <$> (proxyFromDom (Proxy :: Proxy (Union as))))
129+
130+unionFromDom
131+ :: (Monad m, FromDom (Union as))
132+ => proxy as
133+ -> DomParserT Identity m (Union as)
134+unionFromDom _ = fromDom
135+
116136instance FromDom Element where
117137 fromDom = elementFromDom
118138