    {-# LANGUAGE FlexibleInstances, MultiParamTypeClasses, FunctionalDependencies #-}

    -- ------------------------------------------------------------

    {- |
       Module     : Text.XML.HXT.DOM.XmlNode
       Copyright  : Copyright (C) 2008 Uwe Schmidt
       License    : MIT

       Maintainer : Uwe Schmidt (uwe@fh-wedel.de)
       Stability  : stable
       Portability: portable

       Interface for XmlArrow to basic data types NTree and XmlTree

       If this module must be used in code working with arrows,
       it should be imported qualified e.g. @as XN@, to prevent name clashes.

       For code working on the \"node and tree level\" this module
       is the interface for writing code without using the
       constructor functions of 'XNode' and 'NTree' directly

    -}

    -- ------------------------------------------------------------

    module Text.XML.HXT.DOM.XmlNode
        ( module Text.XML.HXT.DOM.XmlNode
        , module Data.Tree.Class
        , module Data.Tree.NTree.TypeDefs
        )
    where

    import Control.Monad
    import Control.FlatSeq

    import Data.Function            ( on )
    import Data.Maybe               ( fromMaybe
                                    , fromJust
                                    )
    import Data.Tree.Class
    import Data.Tree.NTree.TypeDefs

    import Text.XML.HXT.DOM.Interface

    class XmlNode a where
        -- discriminating predicates

        isText              :: a -> Bool
        isBlob              :: a -> Bool
        isCharRef           :: a -> Bool
        isEntityRef         :: a -> Bool
        isCmt               :: a -> Bool
        isCdata             :: a -> Bool
        isPi                :: a -> Bool
        isElem              :: a -> Bool
        isRoot              :: a -> Bool
        isDTD               :: a -> Bool
        isAttr              :: a -> Bool
        isError             :: a -> Bool

        -- constructor functions for leave nodes

        mkText              :: String -> a
        mkBlob              :: Blob   -> a
        mkCharRef           :: Int    -> a
        mkEntityRef         :: String -> a
        mkCmt               :: String -> a
        mkCdata             :: String -> a
        mkPi                :: QName  -> XmlTrees -> a
        mkError             :: Int    -> String   -> a

        -- selectors

        getText             :: a -> Maybe String
        getBlob             :: a -> Maybe Blob
        getCharRef          :: a -> Maybe Int
        getEntityRef        :: a -> Maybe String
        getCmt              :: a -> Maybe String
        getCdata            :: a -> Maybe String
        getPiName           :: a -> Maybe QName
        getPiContent        :: a -> Maybe XmlTrees
        getElemName         :: a -> Maybe QName
        getAttrl            :: a -> Maybe XmlTrees
        getDTDPart          :: a -> Maybe DTDElem
        getDTDAttrl         :: a -> Maybe Attributes
        getAttrName         :: a -> Maybe QName
        getErrorLevel       :: a -> Maybe Int
        getErrorMsg         :: a -> Maybe String

        -- derived selectors

        getName             :: a -> Maybe QName
        getQualifiedName    :: a -> Maybe String
        getUniversalName    :: a -> Maybe String
        getUniversalUri     :: a -> Maybe String
        getLocalPart        :: a -> Maybe String
        getNamePrefix       :: a -> Maybe String
        getNamespaceUri     :: a -> Maybe String

        -- "modifier" functions

        changeText          :: (String   -> String)   -> a -> a
        changeBlob          :: (Blob     -> Blob)     -> a -> a
        changeCmt           :: (String   -> String)   -> a -> a
        changeName          :: (QName    -> QName)    -> a -> a
        changeElemName      :: (QName    -> QName)    -> a -> a
        changeAttrl         :: (XmlTrees -> XmlTrees) -> a -> a
        changeAttrName      :: (QName    -> QName)    -> a -> a
        changePiName        :: (QName    -> QName)    -> a -> a
        changeDTDAttrl      :: (Attributes -> Attributes) -> a -> a

        setText             :: String   -> a -> a
        setBlob             :: Blob     -> a -> a
        setCmt              :: String   -> a -> a
        setName             :: QName    -> a -> a
        setElemName         :: QName    -> a -> a
        setElemAttrl        :: XmlTrees -> a -> a
        setAttrName         :: QName    -> a -> a
        setPiName           :: QName    -> a -> a
        setDTDAttrl         :: Attributes -> a -> a

        -- default implementations

        getName n :: a
    n           = a -> Maybe QName
    forall a. XmlNode a => a -> Maybe QName
    getElemName a
    n Maybe QName -> Maybe QName -> Maybe QName
    forall (m :: * -> *) a. MonadPlus m => m a -> m a -> m a
    `mplus` a -> Maybe QName
    forall a. XmlNode a => a -> Maybe QName
    getAttrName a
    n Maybe QName -> Maybe QName -> Maybe QName
    forall (m :: * -> *) a. MonadPlus m => m a -> m a -> m a
    `mplus` a -> Maybe QName
    forall a. XmlNode a => a -> Maybe QName
    getPiName a
    n
        getQualifiedName n :: a
    n  = a -> Maybe QName
    forall a. XmlNode a => a -> Maybe QName
    getName a
    n Maybe QName -> (QName -> Maybe String) -> Maybe String
    forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
    >>= String -> Maybe String
    forall (m :: * -> *) a. Monad m => a -> m a
    return (String -> Maybe String)
    -> (QName -> String) -> QName -> Maybe String
    forall b c a. (b -> c) -> (a -> b) -> a -> c
    . QName -> String
    qualifiedName
        getUniversalName n :: a
    n  = a -> Maybe QName
    forall a. XmlNode a => a -> Maybe QName
    getName a
    n Maybe QName -> (QName -> Maybe String) -> Maybe String
    forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
    >>= String -> Maybe String
    forall (m :: * -> *) a. Monad m => a -> m a
    return (String -> Maybe String)
    -> (QName -> String) -> QName -> Maybe String
    forall b c a. (b -> c) -> (a -> b) -> a -> c
    . QName -> String
    universalName
        getUniversalUri n :: a
    n   = a -> Maybe QName
    forall a. XmlNode a => a -> Maybe QName
    getName a
    n Maybe QName -> (QName -> Maybe String) -> Maybe String
    forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
    >>= String -> Maybe String
    forall (m :: * -> *) a. Monad m => a -> m a
    return (String -> Maybe String)
    -> (QName -> String) -> QName -> Maybe String
    forall b c a. (b -> c) -> (a -> b) -> a -> c
    . QName -> String
    universalUri
        getLocalPart n :: a
    n      = a -> Maybe QName
    forall a. XmlNode a => a -> Maybe QName
    getName a
    n Maybe QName -> (QName -> Maybe String) -> Maybe String
    forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
    >>= String -> Maybe String
    forall (m :: * -> *) a. Monad m => a -> m a
    return (String -> Maybe String)
    -> (QName -> String) -> QName -> Maybe String
    forall b c a. (b -> c) -> (a -> b) -> a -> c
    . QName -> String
    localPart
        getNamePrefix n :: a
    n     = a -> Maybe QName
    forall a. XmlNode a => a -> Maybe QName
    getName a
    n Maybe QName -> (QName -> Maybe String) -> Maybe String
    forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
    >>= String -> Maybe String
    forall (m :: * -> *) a. Monad m => a -> m a
    return (String -> Maybe String)
    -> (QName -> String) -> QName -> Maybe String
    forall b c a. (b -> c) -> (a -> b) -> a -> c
    . QName -> String
    namePrefix
        getNamespaceUri n :: a
    n   = a -> Maybe QName
    forall a. XmlNode a => a -> Maybe QName
    getName a
    n Maybe QName -> (QName -> Maybe String) -> Maybe String
    forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
    >>= String -> Maybe String
    forall (m :: * -> *) a. Monad m => a -> m a
    return (String -> Maybe String)
    -> (QName -> String) -> QName -> Maybe String
    forall b c a. (b -> c) -> (a -> b) -> a -> c
    . QName -> String
    namespaceUri

        setText             = (String -> String) -> a -> a
    forall a. XmlNode a => (String -> String) -> a -> a
    changeText     ((String -> String) -> a -> a)
    -> (String -> String -> String) -> String -> a -> a
    forall b c a. (b -> c) -> (a -> b) -> a -> c
    . String -> String -> String
    forall a b. a -> b -> a
    const
        setBlob             = (Blob -> Blob) -> a -> a
    forall a. XmlNode a => (Blob -> Blob) -> a -> a
    changeBlob     ((Blob -> Blob) -> a -> a)
    -> (Blob -> Blob -> Blob) -> Blob -> a -> a
    forall b c a. (b -> c) -> (a -> b) -> a -> c
    . Blob -> Blob -> Blob
    forall a b. a -> b -> a
    const
        setCmt              = (String -> String) -> a -> a
    forall a. XmlNode a => (String -> String) -> a -> a
    changeCmt      ((String -> String) -> a -> a)
    -> (String -> String -> String) -> String -> a -> a
    forall b c a. (b -> c) -> (a -> b) -> a -> c
    . String -> String -> String
    forall a b. a -> b -> a
    const
        setName             = (QName -> QName) -> a -> a
    forall a. XmlNode a => (QName -> QName) -> a -> a
    changeName     ((QName -> QName) -> a -> a)
    -> (QName -> QName -> QName) -> QName -> a -> a
    forall b c a. (b -> c) -> (a -> b) -> a -> c
    . QName -> QName -> QName
    forall a b. a -> b -> a
    const
        setElemName         = (QName -> QName) -> a -> a
    forall a. XmlNode a => (QName -> QName) -> a -> a
    changeElemName ((QName -> QName) -> a -> a)
    -> (QName -> QName -> QName) -> QName -> a -> a
    forall b c a. (b -> c) -> (a -> b) -> a -> c
    . QName -> QName -> QName
    forall a b. a -> b -> a
    const
        setElemAttrl        = (XmlTrees -> XmlTrees) -> a -> a
    forall a. XmlNode a => (XmlTrees -> XmlTrees) -> a -> a
    changeAttrl    ((XmlTrees -> XmlTrees) -> a -> a)
    -> (XmlTrees -> XmlTrees -> XmlTrees) -> XmlTrees -> a -> a
    forall b c a. (b -> c) -> (a -> b) -> a -> c
    . XmlTrees -> XmlTrees -> XmlTrees
    forall a b. a -> b -> a
    const
        setAttrName         = (QName -> QName) -> a -> a
    forall a. XmlNode a => (QName -> QName) -> a -> a
    changeAttrName ((QName -> QName) -> a -> a)
    -> (QName -> QName -> QName) -> QName -> a -> a
    forall b c a. (b -> c) -> (a -> b) -> a -> c
    . QName -> QName -> QName
    forall a b. a -> b -> a
    const
        setPiName           = (QName -> QName) -> a -> a
    forall a. XmlNode a => (QName -> QName) -> a -> a
    changePiName   ((QName -> QName) -> a -> a)
    -> (QName -> QName -> QName) -> QName -> a -> a
    forall b c a. (b -> c) -> (a -> b) -> a -> c
    . QName -> QName -> QName
    forall a b. a -> b -> a
    const
        setDTDAttrl         = (Attributes -> Attributes) -> a -> a
    forall a. XmlNode a => (Attributes -> Attributes) -> a -> a
    changeDTDAttrl ((Attributes -> Attributes) -> a -> a)
    -> (Attributes -> Attributes -> Attributes) -> Attributes -> a -> a
    forall b c a. (b -> c) -> (a -> b) -> a -> c
    . Attributes -> Attributes -> Attributes
    forall a b. a -> b -> a
    const

    -- XNode and XmlTree are instances of XmlNode

    instance XmlNode XNode where
        isText :: XNode -> Bool
    isText (XText _)            = Bool
    True
        isText (XBlob _)            = Bool
    True
        isText _                    = Bool
    False
        {-# INLINE isText #-}

        isBlob :: XNode -> Bool
    isBlob (XBlob _)            = Bool
    True
        isBlob _                    = Bool
    False
        {-# INLINE isBlob #-}

        isCharRef :: XNode -> Bool
    isCharRef (XCharRef _)      = Bool
    True
        isCharRef _                 = Bool
    False
        {-# INLINE isCharRef #-}

        isEntityRef :: XNode -> Bool
    isEntityRef (XEntityRef _)  = Bool
    True
        isEntityRef _               = Bool
    False
        {-# INLINE isEntityRef #-}

        isCmt :: XNode -> Bool
    isCmt (XCmt _)              = Bool
    True
        isCmt _                     = Bool
    False
        {-# INLINE isCmt #-}

        isCdata :: XNode -> Bool
    isCdata (XCdata _)          = Bool
    True
        isCdata _                   = Bool
    False
        {-# INLINE isCdata #-}

        isPi :: XNode -> Bool
    isPi (XPi _ _)              = Bool
    True
        isPi _                      = Bool
    False
        {-# INLINE isPi #-}

        isElem :: XNode -> Bool
    isElem (XTag _ _)           = Bool
    True
        isElem _                    = Bool
    False
        {-# INLINE isElem #-}

        isRoot :: XNode -> Bool
    isRoot t :: XNode
    t                    = XNode -> Bool
    forall a. XmlNode a => a -> Bool
    isElem XNode
    t
                                      Bool -> Bool -> Bool
    &&
                                      String -> Maybe String -> String
    forall a. a -> Maybe a -> a
    fromMaybe "" (XNode -> Maybe String
    forall a. XmlNode a => a -> Maybe String
    getQualifiedName XNode
    t) String -> String -> Bool
    forall a. Eq a => a -> a -> Bool
    == String
    t_root

        isDTD :: XNode -> Bool
    isDTD (XDTD _ _)            = Bool
    True
        isDTD _                     = Bool
    False
        {-# INLINE isDTD #-}

        isAttr :: XNode -> Bool
    isAttr (XAttr _)            = Bool
    True
        isAttr _                    = Bool
    False
        {-# INLINE isAttr #-}

        isError :: XNode -> Bool
    isError (XError _ _)        = Bool
    True
        isError _                   = Bool
    False
        {-# INLINE isError #-}

        mkText :: String -> XNode
    mkText                      = String -> XNode
    XText
        {-# INLINE mkText #-}
        mkBlob :: Blob -> XNode
    mkBlob                      = Blob -> XNode
    XBlob
        {-# INLINE mkBlob #-}
        mkCharRef :: Int -> XNode
    mkCharRef                   = Int -> XNode
    XCharRef
        {-# INLINE mkCharRef #-}
        mkEntityRef :: String -> XNode
    mkEntityRef                 = String -> XNode
    XEntityRef
        {-# INLINE mkEntityRef #-}
        mkCmt :: String -> XNode
    mkCmt                       = String -> XNode
    XCmt
        {-# INLINE mkCmt #-}
        mkCdata :: String -> XNode
    mkCdata                     = String -> XNode
    XCdata
        {-# INLINE mkCdata #-}
        mkPi :: QName -> XmlTrees -> XNode
    mkPi                        = QName -> XmlTrees -> XNode
    XPi
        {-# INLINE mkPi #-}

        mkError :: Int -> String -> XNode
    mkError                     = Int -> String -> XNode
    XError
        {-# INLINE mkError #-}

        getText :: XNode -> Maybe String
    getText (XText t :: String
    t)           = String -> Maybe String
    forall a. a -> Maybe a
    Just   String
    t
        getText (XBlob b :: Blob
    b)           = String -> Maybe String
    forall a. a -> Maybe a
    Just (String -> Maybe String)
    -> (Blob -> String) -> Blob -> Maybe String
    forall b c a. (b -> c) -> (a -> b) -> a -> c
    . Blob -> String
    blobToString (Blob -> Maybe String) -> Blob -> Maybe String
    forall a b. (a -> b) -> a -> b
    $ Blob
    b
        getText _                   = Maybe String
    forall a. Maybe a
    Nothing
        {-# INLINE getText #-}

        getBlob :: XNode -> Maybe Blob
    getBlob (XBlob b :: Blob
    b)           = Blob -> Maybe Blob
    forall a. a -> Maybe a
    Just Blob
    b
        getBlob _                   = Maybe Blob
    forall a. Maybe a
    Nothing
        {-# INLINE getBlob #-}

        getCharRef :: XNode -> Maybe Int
    getCharRef (XCharRef c :: Int
    c)     = Int -> Maybe Int
    forall a. a -> Maybe a
    Just Int
    c
        getCharRef _                = Maybe Int
    forall a. Maybe a
    Nothing
        {-# INLINE getCharRef #-}

        getEntityRef :: XNode -> Maybe String
    getEntityRef (XEntityRef e :: String
    e) = String -> Maybe String
    forall a. a -> Maybe a
    Just String
    e
        getEntityRef _              = Maybe String
    forall a. Maybe a
    Nothing
        {-# INLINE getEntityRef #-}

        getCmt :: XNode -> Maybe String
    getCmt (XCmt c :: String
    c)             = String -> Maybe String
    forall a. a -> Maybe a
    Just String
    c
        getCmt _                    = Maybe String
    forall a. Maybe a
    Nothing
        {-# INLINE getCmt #-}

        getCdata :: XNode -> Maybe String
    getCdata (XCdata d :: String
    d)         = String -> Maybe String
    forall a. a -> Maybe a
    Just String
    d
        getCdata _                  = Maybe String
    forall a. Maybe a
    Nothing
        {-# INLINE getCdata #-}

        getPiName :: XNode -> Maybe QName
    getPiName (XPi n :: QName
    n _)         = QName -> Maybe QName
    forall a. a -> Maybe a
    Just QName
    n
        getPiName _                 = Maybe QName
    forall a. Maybe a
    Nothing
        {-# INLINE getPiName #-}

        getPiContent :: XNode -> Maybe XmlTrees
    getPiContent (XPi _ c :: XmlTrees
    c)      = XmlTrees -> Maybe XmlTrees
    forall a. a -> Maybe a
    Just XmlTrees
    c
        getPiContent _              = Maybe XmlTrees
    forall a. Maybe a
    Nothing
        {-# INLINE getPiContent #-}

        getElemName :: XNode -> Maybe QName
    getElemName (XTag n :: QName
    n _)      = QName -> Maybe QName
    forall a. a -> Maybe a
    Just QName
    n
        getElemName _               = Maybe QName
    forall a. Maybe a
    Nothing
        {-# INLINE getElemName #-}

        getAttrl :: XNode -> Maybe XmlTrees
    getAttrl (XTag _ al :: XmlTrees
    al)        = XmlTrees -> Maybe XmlTrees
    forall a. a -> Maybe a
    Just XmlTrees
    al
        getAttrl (XPi  _ al :: XmlTrees
    al)        = XmlTrees -> Maybe XmlTrees
    forall a. a -> Maybe a
    Just XmlTrees
    al
        getAttrl _                  = Maybe XmlTrees
    forall a. Maybe a
    Nothing
        {-# INLINE getAttrl #-}

        getDTDPart :: XNode -> Maybe DTDElem
    getDTDPart (XDTD p :: DTDElem
    p _)       = DTDElem -> Maybe DTDElem
    forall a. a -> Maybe a
    Just DTDElem
    p
        getDTDPart _                = Maybe DTDElem
    forall a. Maybe a
    Nothing
        {-# INLINE getDTDPart #-}

        getDTDAttrl :: XNode -> Maybe Attributes
    getDTDAttrl (XDTD _ al :: Attributes
    al)     = Attributes -> Maybe Attributes
    forall a. a -> Maybe a
    Just Attributes
    al
        getDTDAttrl _               = Maybe Attributes
    forall a. Maybe a
    Nothing
        {-# INLINE getDTDAttrl #-}

        getAttrName :: XNode -> Maybe QName
    getAttrName (XAttr n :: QName
    n)       = QName -> Maybe QName
    forall a. a -> Maybe a
    Just QName
    n
        getAttrName _               = Maybe QName
    forall a. Maybe a
    Nothing
        {-# INLINE getAttrName #-}

        getErrorLevel :: XNode -> Maybe Int
    getErrorLevel (XError l :: Int
    l _)  = Int -> Maybe Int
    forall a. a -> Maybe a
    Just Int
    l
        getErrorLevel _             = Maybe Int
    forall a. Maybe a
    Nothing
        {-# INLINE getErrorLevel #-}

        getErrorMsg :: XNode -> Maybe String
    getErrorMsg (XError _ m :: String
    m)    = String -> Maybe String
    forall a. a -> Maybe a
    Just String
    m
        getErrorMsg _               = Maybe String
    forall a. Maybe a
    Nothing
        {-# INLINE getErrorMsg #-}

        changeText :: (String -> String) -> XNode -> XNode
    changeText cf :: String -> String
    cf (XText t :: String
    t)             = String -> XNode
    XText (String -> XNode) -> (String -> String) -> String -> XNode
    forall b c a. (b -> c) -> (a -> b) -> a -> c
    . String -> String
    cf (String -> XNode) -> String -> XNode
    forall a b. (a -> b) -> a -> b
    $ String
    t
        changeText cf :: String -> String
    cf (XBlob b :: Blob
    b)             = String -> XNode
    XText (String -> XNode) -> (Blob -> String) -> Blob -> XNode
    forall b c a. (b -> c) -> (a -> b) -> a -> c
    . String -> String
    cf (String -> String) -> (Blob -> String) -> Blob -> String
    forall b c a. (b -> c) -> (a -> b) -> a -> c
    . Blob -> String
    blobToString (Blob -> XNode) -> Blob -> XNode
    forall a b. (a -> b) -> a -> b
    $ Blob
    b
        changeText _ _                      = String -> XNode
    forall a. HasCallStack => String -> a
    error "changeText undefined"
        {-# INLINE changeText #-}

        changeBlob :: (Blob -> Blob) -> XNode -> XNode
    changeBlob cf :: Blob -> Blob
    cf (XBlob b :: Blob
    b)             = Blob -> XNode
    XBlob (Blob -> XNode) -> (Blob -> Blob) -> Blob -> XNode
    forall b c a. (b -> c) -> (a -> b) -> a -> c
    . Blob -> Blob
    cf (Blob -> XNode) -> Blob -> XNode
    forall a b. (a -> b) -> a -> b
    $ Blob
    b
        changeBlob _ _                      = String -> XNode
    forall a. HasCallStack => String -> a
    error "changeBlob undefined"
        {-# INLINE changeBlob #-}

        changeCmt :: (String -> String) -> XNode -> XNode
    changeCmt cf :: String -> String
    cf (XCmt c :: String
    c)               = String -> XNode
    XCmt  (String -> XNode) -> (String -> String) -> String -> XNode
    forall b c a. (b -> c) -> (a -> b) -> a -> c
    . String -> String
    cf (String -> XNode) -> String -> XNode
    forall a b. (a -> b) -> a -> b
    $ String
    c
        changeCmt _ _                       = String -> XNode
    forall a. HasCallStack => String -> a
    error "changeCmt undefined"
        {-# INLINE changeCmt #-}

        changeName :: (QName -> QName) -> XNode -> XNode
    changeName cf :: QName -> QName
    cf (XTag n :: QName
    n al :: XmlTrees
    al)           = QName -> XmlTrees -> XNode
    XTag   (QName -> QName
    cf QName
    n) XmlTrees
    al
        changeName cf :: QName -> QName
    cf (XAttr n :: QName
    n)             = QName -> XNode
    XAttr (QName -> XNode) -> (QName -> QName) -> QName -> XNode
    forall b c a. (b -> c) -> (a -> b) -> a -> c
    . QName -> QName
    cf (QName -> XNode) -> QName -> XNode
    forall a b. (a -> b) -> a -> b
    $ QName
    n
        changeName cf :: QName -> QName
    cf (XPi n :: QName
    n al :: XmlTrees
    al)            = QName -> XmlTrees -> XNode
    XPi    (QName -> QName
    cf QName
    n) XmlTrees
    al
        changeName _ _                      = String -> XNode
    forall a. HasCallStack => String -> a
    error "changeName undefined"
        {-# INLINE changeName #-}

        changeElemName :: (QName -> QName) -> XNode -> XNode
    changeElemName cf :: QName -> QName
    cf (XTag n :: QName
    n al :: XmlTrees
    al)       = QName -> XmlTrees -> XNode
    XTag   (QName -> QName
    cf QName
    n) XmlTrees
    al
        changeElemName _ _                  = String -> XNode
    forall a. HasCallStack => String -> a
    error "changeElemName undefined"
        {-# INLINE changeElemName #-}

        changeAttrl :: (XmlTrees -> XmlTrees) -> XNode -> XNode
    changeAttrl cf :: XmlTrees -> XmlTrees
    cf (XTag n :: QName
    n al :: XmlTrees
    al)          = QName -> XmlTrees -> XNode
    XTag QName
    n (XmlTrees -> XmlTrees
    cf XmlTrees
    al)
        changeAttrl cf :: XmlTrees -> XmlTrees
    cf (XPi  n :: QName
    n al :: XmlTrees
    al)          = QName -> XmlTrees -> XNode
    XPi  QName
    n (XmlTrees -> XmlTrees
    cf XmlTrees
    al)
        changeAttrl _ _                     = String -> XNode
    forall a. HasCallStack => String -> a
    error "changeAttrl undefined"
        {-# INLINE changeAttrl #-}

        changeAttrName :: (QName -> QName) -> XNode -> XNode
    changeAttrName cf :: QName -> QName
    cf (XAttr n :: QName
    n)         = QName -> XNode
    XAttr (QName -> XNode) -> (QName -> QName) -> QName -> XNode
    forall b c a. (b -> c) -> (a -> b) -> a -> c
    . QName -> QName
    cf (QName -> XNode) -> QName -> XNode
    forall a b. (a -> b) -> a -> b
    $ QName
    n
        changeAttrName _ _                  = String -> XNode
    forall a. HasCallStack => String -> a
    error "changeAttrName undefined"
        {-# INLINE changeAttrName #-}

        changePiName :: (QName -> QName) -> XNode -> XNode
    changePiName cf :: QName -> QName
    cf (XPi n :: QName
    n al :: XmlTrees
    al)          = QName -> XmlTrees -> XNode
    XPi    (QName -> QName
    cf QName
    n) XmlTrees
    al
        changePiName _ _                    = String -> XNode
    forall a. HasCallStack => String -> a
    error "changePiName undefined"
        {-# INLINE changePiName #-}

        changeDTDAttrl :: (Attributes -> Attributes) -> XNode -> XNode
    changeDTDAttrl cf :: Attributes -> Attributes
    cf (XDTD p :: DTDElem
    p al :: Attributes
    al)       = DTDElem -> Attributes -> XNode
    XDTD DTDElem
    p (Attributes -> Attributes
    cf Attributes
    al)
        changeDTDAttrl _ _                  = String -> XNode
    forall a. HasCallStack => String -> a
    error "changeDTDAttrl undefined"
        {-# INLINE changeDTDAttrl #-}

    mkElementNode   :: QName -> XmlTrees -> XNode
    mkElementNode :: QName -> XmlTrees -> XNode
    mkElementNode   = QName -> XmlTrees -> XNode
    XTag
    {-# INLINE mkElementNode #-}

    mkAttrNode      :: QName -> XNode
    mkAttrNode :: QName -> XNode
    mkAttrNode      = QName -> XNode
    XAttr
    {-# INLINE mkAttrNode #-}

    mkDTDNode       :: DTDElem -> Attributes -> XNode
    mkDTDNode :: DTDElem -> Attributes -> XNode
    mkDTDNode       = DTDElem -> Attributes -> XNode
    XDTD
    {-# INLINE mkDTDNode #-}

    instance (XmlNode a, Tree t) => XmlNode (t a) where
        isText :: t a -> Bool
    isText              = a -> Bool
    forall a. XmlNode a => a -> Bool
    isText      (a -> Bool) -> (t a -> a) -> t a -> Bool
    forall b c a. (b -> c) -> (a -> b) -> a -> c
    . t a -> a
    forall (t :: * -> *) a. Tree t => t a -> a
    getNode
        {-# INLINE isText #-}
        isBlob :: t a -> Bool
    isBlob              = a -> Bool
    forall a. XmlNode a => a -> Bool
    isBlob      (a -> Bool) -> (t a -> a) -> t a -> Bool
    forall b c a. (b -> c) -> (a -> b) -> a -> c
    . t a -> a
    forall (t :: * -> *) a. Tree t => t a -> a
    getNode
        {-# INLINE isBlob #-}
        isCharRef :: t a -> Bool
    isCharRef           = a -> Bool
    forall a. XmlNode a => a -> Bool
    isCharRef   (a -> Bool) -> (t a -> a) -> t a -> Bool
    forall b c a. (b -> c) -> (a -> b) -> a -> c
    . t a -> a
    forall (t :: * -> *) a. Tree t => t a -> a
    getNode
        {-# INLINE isCharRef #-}
        isEntityRef :: t a -> Bool
    isEntityRef         = a -> Bool
    forall a. XmlNode a => a -> Bool
    isEntityRef (a -> Bool) -> (t a -> a) -> t a -> Bool
    forall b c a. (b -> c) -> (a -> b) -> a -> c
    . t a -> a
    forall (t :: * -> *) a. Tree t => t a -> a
    getNode
        {-# INLINE isEntityRef #-}
        isCmt :: t a -> Bool
    isCmt               = a -> Bool
    forall a. XmlNode a => a -> Bool
    isCmt       (a -> Bool) -> (t a -> a) -> t a -> Bool
    forall b c a. (b -> c) -> (a -> b) -> a -> c
    . t a -> a
    forall (t :: * -> *) a. Tree t => t a -> a
    getNode
        {-# INLINE isCmt #-}
        isCdata :: t a -> Bool
    isCdata             = a -> Bool
    forall a. XmlNode a => a -> Bool
    isCdata     (a -> Bool) -> (t a -> a) -> t a -> Bool
    forall b c a. (b -> c) -> (a -> b) -> a -> c
    . t a -> a
    forall (t :: * -> *) a. Tree t => t a -> a
    getNode
        {-# INLINE isCdata #-}
        isPi :: t a -> Bool
    isPi                = a -> Bool
    forall a. XmlNode a => a -> Bool
    isPi        (a -> Bool) -> (t a -> a) -> t a -> Bool
    forall b c a. (b -> c) -> (a -> b) -> a -> c
    . t a -> a
    forall (t :: * -> *) a. Tree t => t a -> a
    getNode
        {-# INLINE isPi #-}
        isElem :: t a -> Bool
    isElem              = a -> Bool
    forall a. XmlNode a => a -> Bool
    isElem      (a -> Bool) -> (t a -> a) -> t a -> Bool
    forall b c a. (b -> c) -> (a -> b) -> a -> c
    . t a -> a
    forall (t :: * -> *) a. Tree t => t a -> a
    getNode
        {-# INLINE isElem #-}
        isRoot :: t a -> Bool
    isRoot              = a -> Bool
    forall a. XmlNode a => a -> Bool
    isRoot      (a -> Bool) -> (t a -> a) -> t a -> Bool
    forall b c a. (b -> c) -> (a -> b) -> a -> c
    . t a -> a
    forall (t :: * -> *) a. Tree t => t a -> a
    getNode
        {-# INLINE isRoot #-}
        isDTD :: t a -> Bool
    isDTD               = a -> Bool
    forall a. XmlNode a => a -> Bool
    isDTD       (a -> Bool) -> (t a -> a) -> t a -> Bool
    forall b c a. (b -> c) -> (a -> b) -> a -> c
    . t a -> a
    forall (t :: * -> *) a. Tree t => t a -> a
    getNode
        {-# INLINE isDTD #-}
        isAttr :: t a -> Bool
    isAttr              = a -> Bool
    forall a. XmlNode a => a -> Bool
    isAttr      (a -> Bool) -> (t a -> a) -> t a -> Bool
    forall b c a. (b -> c) -> (a -> b) -> a -> c
    . t a -> a
    forall (t :: * -> *) a. Tree t => t a -> a
    getNode
        {-# INLINE isAttr #-}
        isError :: t a -> Bool
    isError             = a -> Bool
    forall a. XmlNode a => a -> Bool
    isError     (a -> Bool) -> (t a -> a) -> t a -> Bool
    forall b c a. (b -> c) -> (a -> b) -> a -> c
    . t a -> a
    forall (t :: * -> *) a. Tree t => t a -> a
    getNode
        {-# INLINE isError #-}

        mkText :: String -> t a
    mkText              = a -> t a
    forall (t :: * -> *) a. Tree t => a -> t a
    mkLeaf (a -> t a) -> (String -> a) -> String -> t a
    forall b c a. (b -> c) -> (a -> b) -> a -> c
    . String -> a
    forall a. XmlNode a => String -> a
    mkText
        {-# INLINE mkText #-}
        mkBlob :: Blob -> t a
    mkBlob              = a -> t a
    forall (t :: * -> *) a. Tree t => a -> t a
    mkLeaf (a -> t a) -> (Blob -> a) -> Blob -> t a
    forall b c a. (b -> c) -> (a -> b) -> a -> c
    . Blob -> a
    forall a. XmlNode a => Blob -> a
    mkBlob
        {-# INLINE mkBlob #-}
        mkCharRef :: Int -> t a
    mkCharRef           = a -> t a
    forall (t :: * -> *) a. Tree t => a -> t a
    mkLeaf (a -> t a) -> (Int -> a) -> Int -> t a
    forall b c a. (b -> c) -> (a -> b) -> a -> c
    . Int -> a
    forall a. XmlNode a => Int -> a
    mkCharRef
        {-# INLINE mkCharRef #-}
        mkEntityRef :: String -> t a
    mkEntityRef         = a -> t a
    forall (t :: * -> *) a. Tree t => a -> t a
    mkLeaf (a -> t a) -> (String -> a) -> String -> t a
    forall b c a. (b -> c) -> (a -> b) -> a -> c
    . String -> a
    forall a. XmlNode a => String -> a
    mkEntityRef
        {-# INLINE mkEntityRef #-}
        mkCmt :: String -> t a
    mkCmt               = a -> t a
    forall (t :: * -> *) a. Tree t => a -> t a
    mkLeaf (a -> t a) -> (String -> a) -> String -> t a
    forall b c a. (b -> c) -> (a -> b) -> a -> c
    . String -> a
    forall a. XmlNode a => String -> a
    mkCmt
        {-# INLINE mkCmt #-}
        mkCdata :: String -> t a
    mkCdata             = a -> t a
    forall (t :: * -> *) a. Tree t => a -> t a
    mkLeaf (a -> t a) -> (String -> a) -> String -> t a
    forall b c a. (b -> c) -> (a -> b) -> a -> c
    . String -> a
    forall a. XmlNode a => String -> a
    mkCdata
        {-# INLINE mkCdata #-}
        mkPi :: QName -> XmlTrees -> t a
    mkPi n :: QName
    n              = a -> t a
    forall (t :: * -> *) a. Tree t => a -> t a
    mkLeaf (a -> t a) -> (XmlTrees -> a) -> XmlTrees -> t a
    forall b c a. (b -> c) -> (a -> b) -> a -> c
    . QName -> XmlTrees -> a
    forall a. XmlNode a => QName -> XmlTrees -> a
    mkPi QName
    n
        {-# INLINE mkPi #-}
        mkError :: Int -> String -> t a
    mkError l :: Int
    l           = a -> t a
    forall (t :: * -> *) a. Tree t => a -> t a
    mkLeaf (a -> t a) -> (String -> a) -> String -> t a
    forall b c a. (b -> c) -> (a -> b) -> a -> c
    . Int -> String -> a
    forall a. XmlNode a => Int -> String -> a
    mkError Int
    l
        {-# INLINE mkError #-}

        getText :: t a -> Maybe String
    getText             = a -> Maybe String
    forall a. XmlNode a => a -> Maybe String
    getText       (a -> Maybe String) -> (t a -> a) -> t a -> Maybe String
    forall b c a. (b -> c) -> (a -> b) -> a -> c
    . t a -> a
    forall (t :: * -> *) a. Tree t => t a -> a
    getNode
        {-# INLINE getText #-}
        getBlob :: t a -> Maybe Blob
    getBlob             = a -> Maybe Blob
    forall a. XmlNode a => a -> Maybe Blob
    getBlob       (a -> Maybe Blob) -> (t a -> a) -> t a -> Maybe Blob
    forall b c a. (b -> c) -> (a -> b) -> a -> c
    . t a -> a
    forall (t :: * -> *) a. Tree t => t a -> a
    getNode
        {-# INLINE getBlob #-}
        getCharRef :: t a -> Maybe Int
    getCharRef          = a -> Maybe Int
    forall a. XmlNode a => a -> Maybe Int
    getCharRef    (a -> Maybe Int) -> (t a -> a) -> t a -> Maybe Int
    forall b c a. (b -> c) -> (a -> b) -> a -> c
    . t a -> a
    forall (t :: * -> *) a. Tree t => t a -> a
    getNode
        {-# INLINE getCharRef #-}
        getEntityRef :: t a -> Maybe String
    getEntityRef        = a -> Maybe String
    forall a. XmlNode a => a -> Maybe String
    getEntityRef  (a -> Maybe String) -> (t a -> a) -> t a -> Maybe String
    forall b c a. (b -> c) -> (a -> b) -> a -> c
    . t a -> a
    forall (t :: * -> *) a. Tree t => t a -> a
    getNode
        {-# INLINE getEntityRef #-}
        getCmt :: t a -> Maybe String
    getCmt              = a -> Maybe String
    forall a. XmlNode a => a -> Maybe String
    getCmt        (a -> Maybe String) -> (t a -> a) -> t a -> Maybe String
    forall b c a. (b -> c) -> (a -> b) -> a -> c
    . t a -> a
    forall (t :: * -> *) a. Tree t => t a -> a
    getNode
        {-# INLINE getCmt #-}
        getCdata :: t a -> Maybe String
    getCdata            = a -> Maybe String
    forall a. XmlNode a => a -> Maybe String
    getCdata      (a -> Maybe String) -> (t a -> a) -> t a -> Maybe String
    forall b c a. (b -> c) -> (a -> b) -> a -> c
    . t a -> a
    forall (t :: * -> *) a. Tree t => t a -> a
    getNode
        {-# INLINE getCdata #-}
        getPiName :: t a -> Maybe QName
    getPiName           = a -> Maybe QName
    forall a. XmlNode a => a -> Maybe QName
    getPiName     (a -> Maybe QName) -> (t a -> a) -> t a -> Maybe QName
    forall b c a. (b -> c) -> (a -> b) -> a -> c
    . t a -> a
    forall (t :: * -> *) a. Tree t => t a -> a
    getNode
        {-# INLINE getPiName #-}
        getPiContent :: t a -> Maybe XmlTrees
    getPiContent        = a -> Maybe XmlTrees
    forall a. XmlNode a => a -> Maybe XmlTrees
    getPiContent  (a -> Maybe XmlTrees) -> (t a -> a) -> t a -> Maybe XmlTrees
    forall b c a. (b -> c) -> (a -> b) -> a -> c
    . t a -> a
    forall (t :: * -> *) a. Tree t => t a -> a
    getNode
        {-# INLINE getPiContent #-}
        getElemName :: t a -> Maybe QName
    getElemName         = a -> Maybe QName
    forall a. XmlNode a => a -> Maybe QName
    getElemName   (a -> Maybe QName) -> (t a -> a) -> t a -> Maybe QName
    forall b c a. (b -> c) -> (a -> b) -> a -> c
    . t a -> a
    forall (t :: * -> *) a. Tree t => t a -> a
    getNode
        {-# INLINE getElemName #-}
        getAttrl :: t a -> Maybe XmlTrees
    getAttrl            = a -> Maybe XmlTrees
    forall a. XmlNode a => a -> Maybe XmlTrees
    getAttrl      (a -> Maybe XmlTrees) -> (t a -> a) -> t a -> Maybe XmlTrees
    forall b c a. (b -> c) -> (a -> b) -> a -> c
    . t a -> a
    forall (t :: * -> *) a. Tree t => t a -> a
    getNode
        {-# INLINE getAttrl #-}
        getDTDPart :: t a -> Maybe DTDElem
    getDTDPart          = a -> Maybe DTDElem
    forall a. XmlNode a => a -> Maybe DTDElem
    getDTDPart    (a -> Maybe DTDElem) -> (t a -> a) -> t a -> Maybe DTDElem
    forall b c a. (b -> c) -> (a -> b) -> a -> c
    . t a -> a
    forall (t :: * -> *) a. Tree t => t a -> a
    getNode
        {-# INLINE getDTDPart #-}
        getDTDAttrl :: t a -> Maybe Attributes
    getDTDAttrl         = a -> Maybe Attributes
    forall a. XmlNode a => a -> Maybe Attributes
    getDTDAttrl   (a -> Maybe Attributes) -> (t a -> a) -> t a -> Maybe Attributes
    forall b c a. (b -> c) -> (a -> b) -> a -> c
    . t a -> a
    forall (t :: * -> *) a. Tree t => t a -> a
    getNode
        {-# INLINE getDTDAttrl #-}
        getAttrName :: t a -> Maybe QName
    getAttrName         = a -> Maybe QName
    forall a. XmlNode a => a -> Maybe QName
    getAttrName   (a -> Maybe QName) -> (t a -> a) -> t a -> Maybe QName
    forall b c a. (b -> c) -> (a -> b) -> a -> c
    . t a -> a
    forall (t :: * -> *) a. Tree t => t a -> a
    getNode
        {-# INLINE getAttrName #-}
        getErrorLevel :: t a -> Maybe Int
    getErrorLevel       = a -> Maybe Int
    forall a. XmlNode a => a -> Maybe Int
    getErrorLevel (a -> Maybe Int) -> (t a -> a) -> t a -> Maybe Int
    forall b c a. (b -> c) -> (a -> b) -> a -> c
    . t a -> a
    forall (t :: * -> *) a. Tree t => t a -> a
    getNode
        {-# INLINE getErrorLevel #-}
        getErrorMsg :: t a -> Maybe String
    getErrorMsg         = a -> Maybe String
    forall a. XmlNode a => a -> Maybe String
    getErrorMsg   (a -> Maybe String) -> (t a -> a) -> t a -> Maybe String
    forall b c a. (b -> c) -> (a -> b) -> a -> c
    . t a -> a
    forall (t :: * -> *) a. Tree t => t a -> a
    getNode
        {-# INLINE getErrorMsg #-}

        changeText :: (String -> String) -> t a -> t a
    changeText          = (a -> a) -> t a -> t a
    forall (t :: * -> *) a. Tree t => (a -> a) -> t a -> t a
    changeNode ((a -> a) -> t a -> t a)
    -> ((String -> String) -> a -> a)
    -> (String -> String)
    -> t a
    -> t a
    forall b c a. (b -> c) -> (a -> b) -> a -> c
    . (String -> String) -> a -> a
    forall a. XmlNode a => (String -> String) -> a -> a
    changeText
        {-# INLINE changeText #-}
        changeBlob :: (Blob -> Blob) -> t a -> t a
    changeBlob          = (a -> a) -> t a -> t a
    forall (t :: * -> *) a. Tree t => (a -> a) -> t a -> t a
    changeNode ((a -> a) -> t a -> t a)
    -> ((Blob -> Blob) -> a -> a) -> (Blob -> Blob) -> t a -> t a
    forall b c a. (b -> c) -> (a -> b) -> a -> c
    . (Blob -> Blob) -> a -> a
    forall a. XmlNode a => (Blob -> Blob) -> a -> a
    changeBlob
        {-# INLINE changeBlob #-}
        changeCmt :: (String -> String) -> t a -> t a
    changeCmt           = (a -> a) -> t a -> t a
    forall (t :: * -> *) a. Tree t => (a -> a) -> t a -> t a
    changeNode ((a -> a) -> t a -> t a)
    -> ((String -> String) -> a -> a)
    -> (String -> String)
    -> t a
    -> t a
    forall b c a. (b -> c) -> (a -> b) -> a -> c
    . (String -> String) -> a -> a
    forall a. XmlNode a => (String -> String) -> a -> a
    changeCmt
        {-# INLINE changeCmt #-}
        changeName :: (QName -> QName) -> t a -> t a
    changeName          = (a -> a) -> t a -> t a
    forall (t :: * -> *) a. Tree t => (a -> a) -> t a -> t a
    changeNode ((a -> a) -> t a -> t a)
    -> ((QName -> QName) -> a -> a) -> (QName -> QName) -> t a -> t a
    forall b c a. (b -> c) -> (a -> b) -> a -> c
    . (QName -> QName) -> a -> a
    forall a. XmlNode a => (QName -> QName) -> a -> a
    changeName
        {-# INLINE changeName #-}
        changeElemName :: (QName -> QName) -> t a -> t a
    changeElemName      = (a -> a) -> t a -> t a
    forall (t :: * -> *) a. Tree t => (a -> a) -> t a -> t a
    changeNode ((a -> a) -> t a -> t a)
    -> ((QName -> QName) -> a -> a) -> (QName -> QName) -> t a -> t a
    forall b c a. (b -> c) -> (a -> b) -> a -> c
    . (QName -> QName) -> a -> a
    forall a. XmlNode a => (QName -> QName) -> a -> a
    changeElemName
        {-# INLINE changeElemName #-}
        changeAttrl :: (XmlTrees -> XmlTrees) -> t a -> t a
    changeAttrl         = (a -> a) -> t a -> t a
    forall (t :: * -> *) a. Tree t => (a -> a) -> t a -> t a
    changeNode ((a -> a) -> t a -> t a)
    -> ((XmlTrees -> XmlTrees) -> a -> a)
    -> (XmlTrees -> XmlTrees)
    -> t a
    -> t a
    forall b c a. (b -> c) -> (a -> b) -> a -> c
    . (XmlTrees -> XmlTrees) -> a -> a
    forall a. XmlNode a => (XmlTrees -> XmlTrees) -> a -> a
    changeAttrl
        {-# INLINE changeAttrl #-}
        changeAttrName :: (QName -> QName) -> t a -> t a
    changeAttrName      = (a -> a) -> t a -> t a
    forall (t :: * -> *) a. Tree t => (a -> a) -> t a -> t a
    changeNode ((a -> a) -> t a -> t a)
    -> ((QName -> QName) -> a -> a) -> (QName -> QName) -> t a -> t a
    forall b c a. (b -> c) -> (a -> b) -> a -> c
    . (QName -> QName) -> a -> a
    forall a. XmlNode a => (QName -> QName) -> a -> a
    changeAttrName
        {-# INLINE changeAttrName #-}
        changePiName :: (QName -> QName) -> t a -> t a
    changePiName        = (a -> a) -> t a -> t a
    forall (t :: * -> *) a. Tree t => (a -> a) -> t a -> t a
    changeNode ((a -> a) -> t a -> t a)
    -> ((QName -> QName) -> a -> a) -> (QName -> QName) -> t a -> t a
    forall b c a. (b -> c) -> (a -> b) -> a -> c
    . (QName -> QName) -> a -> a
    forall a. XmlNode a => (QName -> QName) -> a -> a
    changePiName
        {-# INLINE changePiName #-}
        changeDTDAttrl :: (Attributes -> Attributes) -> t a -> t a
    changeDTDAttrl      = (a -> a) -> t a -> t a
    forall (t :: * -> *) a. Tree t => (a -> a) -> t a -> t a
    changeNode ((a -> a) -> t a -> t a)
    -> ((Attributes -> Attributes) -> a -> a)
    -> (Attributes -> Attributes)
    -> t a
    -> t a
    forall b c a. (b -> c) -> (a -> b) -> a -> c
    . (Attributes -> Attributes) -> a -> a
    forall a. XmlNode a => (Attributes -> Attributes) -> a -> a
    changeDTDAttrl
        {-# INLINE changeDTDAttrl #-}

    mkElement       :: QName -> XmlTrees -> XmlTrees -> XmlTree
    mkElement :: QName -> XmlTrees -> XmlTrees -> XmlTree
    mkElement n :: QName
    n al :: XmlTrees
    al  = XNode -> XmlTrees -> XmlTree
    forall (t :: * -> *) a. Tree t => a -> [t a] -> t a
    mkTree (QName -> XmlTrees -> XNode
    mkElementNode QName
    n XmlTrees
    al)
    {-# INLINE mkElement #-}

    mkRoot          :: XmlTrees -> XmlTrees -> XmlTree
    mkRoot :: XmlTrees -> XmlTrees -> XmlTree
    mkRoot al :: XmlTrees
    al       = XNode -> XmlTrees -> XmlTree
    forall (t :: * -> *) a. Tree t => a -> [t a] -> t a
    mkTree (QName -> XmlTrees -> XNode
    mkElementNode (String -> QName
    mkName String
    t_root) XmlTrees
    al)

    mkAttr          :: QName -> XmlTrees -> XmlTree
    mkAttr :: QName -> XmlTrees -> XmlTree
    mkAttr n :: QName
    n        = XNode -> XmlTrees -> XmlTree
    forall (t :: * -> *) a. Tree t => a -> [t a] -> t a
    mkTree (QName -> XNode
    mkAttrNode QName
    n)
    {-# INLINE mkAttr #-}

    mkDTDElem       :: DTDElem -> Attributes -> XmlTrees -> XmlTree
    mkDTDElem :: DTDElem -> Attributes -> XmlTrees -> XmlTree
    mkDTDElem e :: DTDElem
    e al :: Attributes
    al  = XNode -> XmlTrees -> XmlTree
    forall (t :: * -> *) a. Tree t => a -> [t a] -> t a
    mkTree (DTDElem -> Attributes -> XNode
    mkDTDNode DTDElem
    e Attributes
    al)

    addAttr         :: XmlTree -> XmlTrees -> XmlTrees
    addAttr :: XmlTree -> XmlTrees -> XmlTrees
    addAttr a :: XmlTree
    a al :: XmlTrees
    al
        | XmlTree -> Bool
    forall a. XmlNode a => a -> Bool
    isAttr XmlTree
    a  = XmlTrees -> XmlTrees
    add XmlTrees
    al
        | Bool
    otherwise = XmlTrees
    al
        where
        an :: String
    an = (QName -> String
    qualifiedName (QName -> String) -> (XmlTree -> QName) -> XmlTree -> String
    forall b c a. (b -> c) -> (a -> b) -> a -> c
    . Maybe QName -> QName
    forall a. HasCallStack => Maybe a -> a
    fromJust (Maybe QName -> QName)
    -> (XmlTree -> Maybe QName) -> XmlTree -> QName
    forall b c a. (b -> c) -> (a -> b) -> a -> c
    . XmlTree -> Maybe QName
    forall a. XmlNode a => a -> Maybe QName
    getAttrName) XmlTree
    a
        add :: XmlTrees -> XmlTrees
    add []
            = [XmlTree
    a]
        add (a1 :: XmlTree
    a1:al1 :: XmlTrees
    al1)
            | XmlTree -> Bool
    forall a. XmlNode a => a -> Bool
    isAttr XmlTree
    a1
              Bool -> Bool -> Bool
    &&
              (QName -> String
    qualifiedName (QName -> String) -> (XmlTree -> QName) -> XmlTree -> String
    forall b c a. (b -> c) -> (a -> b) -> a -> c
    . Maybe QName -> QName
    forall a. HasCallStack => Maybe a -> a
    fromJust (Maybe QName -> QName)
    -> (XmlTree -> Maybe QName) -> XmlTree -> QName
    forall b c a. (b -> c) -> (a -> b) -> a -> c
    . XmlTree -> Maybe QName
    forall a. XmlNode a => a -> Maybe QName
    getAttrName) XmlTree
    a1 String -> String -> Bool
    forall a. Eq a => a -> a -> Bool
    == String
    an
                = XmlTree
    a XmlTree -> XmlTrees -> XmlTrees
    forall a. a -> [a] -> [a]
    : XmlTrees
    al1
            | Bool
    otherwise
                = XmlTree
    a1 XmlTree -> XmlTrees -> XmlTrees
    forall a. a -> [a] -> [a]
    : XmlTrees -> XmlTrees
    add XmlTrees
    al1

    mergeAttrl      :: XmlTrees -> XmlTrees -> XmlTrees
    mergeAttrl :: XmlTrees -> XmlTrees -> XmlTrees
    mergeAttrl      = (XmlTree -> XmlTrees -> XmlTrees)
    -> XmlTrees -> XmlTrees -> XmlTrees
    forall (t :: * -> *) a b.
    Foldable t =>
    (a -> b -> b) -> b -> t a -> b
    foldr XmlTree -> XmlTrees -> XmlTrees
    addAttr

    -- ------------------------------------------------------------

    -- | weak normalform versions of constructors

    mkElement'              :: QName -> XmlTrees -> XmlTrees -> XmlTree
    mkElement' :: QName -> XmlTrees -> XmlTrees -> XmlTree
    mkElement' n :: QName
    n al :: XmlTrees
    al cl :: XmlTrees
    cl      = XmlTree -> XmlTree
    forall a. a -> a
    id (XmlTree -> XmlTree) -> XmlTree -> XmlTree
    forall a b. WNFData a => (a -> b) -> a -> b
    $!! QName -> XmlTrees -> XmlTrees -> XmlTree
    mkElement QName
    n XmlTrees
    al XmlTrees
    cl
    {-# INLINE mkElement' #-}

    mkRoot'                 :: XmlTrees -> XmlTrees -> XmlTree
    mkRoot' :: XmlTrees -> XmlTrees -> XmlTree
    mkRoot' al :: XmlTrees
    al cl :: XmlTrees
    cl           = XmlTree -> XmlTree
    forall a. a -> a
    id (XmlTree -> XmlTree) -> XmlTree -> XmlTree
    forall a b. WNFData a => (a -> b) -> a -> b
    $!! XmlTrees -> XmlTrees -> XmlTree
    mkRoot XmlTrees
    al XmlTrees
    cl
    {-# INLINE mkRoot' #-}

    mkAttr'                 :: QName -> XmlTrees -> XmlTree
    mkAttr' :: QName -> XmlTrees -> XmlTree
    mkAttr' n :: QName
    n av :: XmlTrees
    av            = XmlTree -> XmlTree
    forall a. a -> a
    id (XmlTree -> XmlTree) -> XmlTree -> XmlTree
    forall a b. WNFData a => (a -> b) -> a -> b
    $!! QName -> XmlTrees -> XmlTree
    mkAttr QName
    n XmlTrees
    av
    {-# INLINE mkAttr' #-}

    mkText'                 :: String -> XmlTree
    mkText' :: String -> XmlTree
    mkText' t :: String
    t               = XmlTree -> XmlTree
    forall a. a -> a
    id (XmlTree -> XmlTree) -> XmlTree -> XmlTree
    forall a b. WNFData a => (a -> b) -> a -> b
    $!! String -> XmlTree
    forall a. XmlNode a => String -> a
    mkText String
    t
    {-# INLINE mkText' #-}

    mkCharRef'              :: Int    -> XmlTree
    mkCharRef' :: Int -> XmlTree
    mkCharRef' i :: Int
    i            = XmlTree -> XmlTree
    forall a. a -> a
    id (XmlTree -> XmlTree) -> XmlTree -> XmlTree
    forall a b. WNFData a => (a -> b) -> a -> b
    $!! Int -> XmlTree
    forall a. XmlNode a => Int -> a
    mkCharRef Int
    i
    {-# INLINE mkCharRef' #-}

    mkEntityRef'            :: String -> XmlTree
    mkEntityRef' :: String -> XmlTree
    mkEntityRef' n :: String
    n          = XmlTree -> XmlTree
    forall a. a -> a
    id (XmlTree -> XmlTree) -> XmlTree -> XmlTree
    forall a b. WNFData a => (a -> b) -> a -> b
    $!! String -> XmlTree
    forall a. XmlNode a => String -> a
    mkEntityRef String
    n
    {-# INLINE mkEntityRef' #-}

    mkCmt'                  :: String -> XmlTree
    mkCmt' :: String -> XmlTree
    mkCmt' c :: String
    c                = XmlTree -> XmlTree
    forall a. a -> a
    id (XmlTree -> XmlTree) -> XmlTree -> XmlTree
    forall a b. WNFData a => (a -> b) -> a -> b
    $!! String -> XmlTree
    forall a. XmlNode a => String -> a
    mkCmt String
    c
    {-# INLINE mkCmt' #-}

    mkCdata'                :: String -> XmlTree
    mkCdata' :: String -> XmlTree
    mkCdata' d :: String
    d              = XmlTree -> XmlTree
    forall a. a -> a
    id (XmlTree -> XmlTree) -> XmlTree -> XmlTree
    forall a b. WNFData a => (a -> b) -> a -> b
    $!! String -> XmlTree
    forall a. XmlNode a => String -> a
    mkCdata String
    d
    {-# INLINE mkCdata' #-}

    mkPi'                   :: QName  -> XmlTrees -> XmlTree
    mkPi' :: QName -> XmlTrees -> XmlTree
    mkPi' n :: QName
    n v :: XmlTrees
    v               = XmlTree -> XmlTree
    forall a. a -> a
    id (XmlTree -> XmlTree) -> XmlTree -> XmlTree
    forall a b. WNFData a => (a -> b) -> a -> b
    $!! QName -> XmlTrees -> XmlTree
    forall a. XmlNode a => QName -> XmlTrees -> a
    mkPi QName
    n XmlTrees
    v
    {-# INLINE mkPi' #-}

    mkError'                :: Int -> String   -> XmlTree
    mkError' :: Int -> String -> XmlTree
    mkError' l :: Int
    l m :: String
    m            = XmlTree -> XmlTree
    forall a. a -> a
    id (XmlTree -> XmlTree) -> XmlTree -> XmlTree
    forall a b. WNFData a => (a -> b) -> a -> b
    $!! Int -> String -> XmlTree
    forall a. XmlNode a => Int -> String -> a
    mkError Int
    l String
    m
    {-# INLINE mkError' #-}

    mkDTDElem'              :: DTDElem -> Attributes -> XmlTrees -> XmlTree
    mkDTDElem' :: DTDElem -> Attributes -> XmlTrees -> XmlTree
    mkDTDElem' e :: DTDElem
    e al :: Attributes
    al cl :: XmlTrees
    cl      = XmlTree -> XmlTree
    forall a. a -> a
    id (XmlTree -> XmlTree) -> XmlTree -> XmlTree
    forall a b. WNFData a => (a -> b) -> a -> b
    $!! DTDElem -> Attributes -> XmlTrees -> XmlTree
    mkDTDElem DTDElem
    e Attributes
    al XmlTrees
    cl
    {-# INLINE mkDTDElem' #-}

    -- ------------------------------------------------------------

    toText :: XmlTree -> XmlTree
    toText :: XmlTree -> XmlTree
    toText t :: XmlTree
    t
        | XmlTree -> Bool
    forall a. XmlNode a => a -> Bool
    isCharRef XmlTree
    t
            = String -> XmlTree
    forall a. XmlNode a => String -> a
    mkText
              (String -> XmlTree) -> (XmlTree -> String) -> XmlTree -> XmlTree
    forall b c a. (b -> c) -> (a -> b) -> a -> c
    . (Char -> String -> String
    forall a. a -> [a] -> [a]
    :[]) (Char -> String) -> (XmlTree -> Char) -> XmlTree -> String
    forall b c a. (b -> c) -> (a -> b) -> a -> c
    . Int -> Char
    forall a. Enum a => Int -> a
    toEnum
              (Int -> Char) -> (XmlTree -> Int) -> XmlTree -> Char
    forall b c a. (b -> c) -> (a -> b) -> a -> c
    . Maybe Int -> Int
    forall a. HasCallStack => Maybe a -> a
    fromJust
              (Maybe Int -> Int) -> (XmlTree -> Maybe Int) -> XmlTree -> Int
    forall b c a. (b -> c) -> (a -> b) -> a -> c
    . XmlTree -> Maybe Int
    forall a. XmlNode a => a -> Maybe Int
    getCharRef
              (XmlTree -> XmlTree) -> XmlTree -> XmlTree
    forall a b. (a -> b) -> a -> b
    $ XmlTree
    t
        | XmlTree -> Bool
    forall a. XmlNode a => a -> Bool
    isCdata XmlTree
    t
            = String -> XmlTree
    forall a. XmlNode a => String -> a
    mkText
              (String -> XmlTree) -> (XmlTree -> String) -> XmlTree -> XmlTree
    forall b c a. (b -> c) -> (a -> b) -> a -> c
    . Maybe String -> String
    forall a. HasCallStack => Maybe a -> a
    fromJust
              (Maybe String -> String)
    -> (XmlTree -> Maybe String) -> XmlTree -> String
    forall b c a. (b -> c) -> (a -> b) -> a -> c
    . XmlTree -> Maybe String
    forall a. XmlNode a => a -> Maybe String
    getCdata
              (XmlTree -> XmlTree) -> XmlTree -> XmlTree
    forall a b. (a -> b) -> a -> b
    $ XmlTree
    t
        | Bool
    otherwise
            = XmlTree
    t

    concText :: XmlTree -> XmlTree -> XmlTrees
    concText :: XmlTree -> XmlTree -> XmlTrees
    concText t1 :: XmlTree
    t1 t2 :: XmlTree
    t2
        | XmlTree -> Bool
    forall a. XmlNode a => a -> Bool
    isText XmlTree
    t1 Bool -> Bool -> Bool
    && XmlTree -> Bool
    forall a. XmlNode a => a -> Bool
    isText XmlTree
    t2
            = (XmlTree -> XmlTrees -> XmlTrees
    forall a. a -> [a] -> [a]
    :[]) (XmlTree -> XmlTrees) -> (String -> XmlTree) -> String -> XmlTrees
    forall b c a. (b -> c) -> (a -> b) -> a -> c
    . String -> XmlTree
    forall a. XmlNode a => String -> a
    mkText (String -> XmlTrees) -> String -> XmlTrees
    forall a b. (a -> b) -> a -> b
    $ Maybe String -> String
    forall a. HasCallStack => Maybe a -> a
    fromJust (XmlTree -> Maybe String
    forall a. XmlNode a => a -> Maybe String
    getText XmlTree
    t1) String -> String -> String
    forall a. [a] -> [a] -> [a]
    ++ Maybe String -> String
    forall a. HasCallStack => Maybe a -> a
    fromJust (XmlTree -> Maybe String
    forall a. XmlNode a => a -> Maybe String
    getText XmlTree
    t2)
        | Bool
    otherwise
            = [XmlTree
    t1, XmlTree
    t2]

    mergeText :: XmlTree -> XmlTree -> XmlTrees
    mergeText :: XmlTree -> XmlTree -> XmlTrees
    mergeText
        = XmlTree -> XmlTree -> XmlTrees
    concText (XmlTree -> XmlTree -> XmlTrees)
    -> (XmlTree -> XmlTree) -> XmlTree -> XmlTree -> XmlTrees
    forall b c a. (b -> b -> c) -> (a -> b) -> a -> a -> c
    `on` XmlTree -> XmlTree
    toText

    -- ------------------------------------------------------------