{-# 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 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 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 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 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 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 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 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 String
_)            = Bool
True
    isText (XBlob Blob
_)            = Bool
True
    isText XNode
_                    = Bool
False
    {-# INLINE isText #-}

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

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

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

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

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

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

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

    isRoot :: XNode -> Bool
isRoot 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 String
"" (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 DTDElem
_ Attributes
_)            = Bool
True
    isDTD XNode
_                     = Bool
False
    {-# INLINE isDTD #-}

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

    isError :: XNode -> Bool
isError (XError Int
_ String
_)        = Bool
True
    isError XNode
_                   = 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 String
t)           = String -> Maybe String
forall a. a -> Maybe a
Just   String
t
    getText (XBlob 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 XNode
_                   = Maybe String
forall a. Maybe a
Nothing
    {-# INLINE getText #-}

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    changeText :: (String -> String) -> XNode -> XNode
changeText String -> String
cf (XText 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 String -> String
cf (XBlob 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 -> String
_ XNode
_                      = String -> XNode
forall a. HasCallStack => String -> a
error String
"changeText undefined"
    {-# INLINE changeText #-}

    changeBlob :: (Blob -> Blob) -> XNode -> XNode
changeBlob Blob -> Blob
cf (XBlob 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 Blob -> Blob
_ XNode
_                      = String -> XNode
forall a. HasCallStack => String -> a
error String
"changeBlob undefined"
    {-# INLINE changeBlob #-}

    changeCmt :: (String -> String) -> XNode -> XNode
changeCmt String -> String
cf (XCmt 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 -> String
_ XNode
_                       = String -> XNode
forall a. HasCallStack => String -> a
error String
"changeCmt undefined"
    {-# INLINE changeCmt #-}

    changeName :: (QName -> QName) -> XNode -> XNode
changeName QName -> QName
cf (XTag QName
n XmlTrees
al)           = QName -> XmlTrees -> XNode
XTag   (QName -> QName
cf QName
n) XmlTrees
al
    changeName QName -> QName
cf (XAttr 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 QName -> QName
cf (XPi QName
n XmlTrees
al)            = QName -> XmlTrees -> XNode
XPi    (QName -> QName
cf QName
n) XmlTrees
al
    changeName QName -> QName
_ XNode
_                      = String -> XNode
forall a. HasCallStack => String -> a
error String
"changeName undefined"
    {-# INLINE changeName #-}

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

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

    changeAttrName :: (QName -> QName) -> XNode -> XNode
changeAttrName QName -> QName
cf (XAttr 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 QName -> QName
_ XNode
_                  = String -> XNode
forall a. HasCallStack => String -> a
error String
"changeAttrName undefined"
    {-# INLINE changeAttrName #-}

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

    changeDTDAttrl :: (Attributes -> Attributes) -> XNode -> XNode
changeDTDAttrl Attributes -> Attributes
cf (XDTD DTDElem
p Attributes
al)       = DTDElem -> Attributes -> XNode
XDTD DTDElem
p (Attributes -> Attributes
cf Attributes
al)
    changeDTDAttrl Attributes -> Attributes
_ XNode
_                  = String -> XNode
forall a. HasCallStack => String -> a
error String
"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 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 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 QName
n 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 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 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 DTDElem
e 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 XmlTree
a 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 (XmlTree
a1: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' QName
n XmlTrees
al 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' XmlTrees
al 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' QName
n 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' 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' 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' 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' 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' 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' QName
n 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' Int
l 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' DTDElem
e Attributes
al 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 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 XmlTree
t1 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

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