{-# LANGUAGE CPP #-}
module Text.XML.HaXml.ShowXmlLazy (showXmlLazy) where

import Text.XML.HaXml.Types
import Text.XML.HaXml.Namespaces
import Text.XML.HaXml.TypeMapping -- (toHType, toDTD, Tuple(), Defined, showHType)

#if MIN_VERSION_base(4,11,0)
import Prelude hiding (maybe,either,(<>))
#else
import Prelude hiding (maybe,either)
#endif

import qualified Text.XML.HaXml.XmlContent as X
import Data.Maybe hiding (maybe)
import Data.List

-- | Convert a fully-typed XML document to a string (without DTD).
showXmlLazy :: X.XmlContent a => Bool -> a -> String
showXmlLazy :: forall a. XmlContent a => Bool -> a -> String
showXmlLazy Bool
dtd a
x =
    case forall a. XmlContent a => a -> [Content ()]
X.toContents a
x of
      [CElem Element ()
_ ()
_] -> forall i. Document i -> String
document forall a b. (a -> b) -> a -> b
$ forall a. XmlContent a => Bool -> a -> Document ()
toXmlLazy Bool
dtd a
x
      [Content ()]
_ -> String
""


-- | Convert a fully-typed XML document to a string (with or without DTD).
toXmlLazy :: X.XmlContent a => Bool -> a -> Document ()
toXmlLazy :: forall a. XmlContent a => Bool -> a -> Document ()
toXmlLazy Bool
dtd a
value =
    let ht :: HType
ht = forall a. HTypeable a => a -> HType
toHType a
value in
    forall i.
Prolog -> SymTab EntityDef -> Element i -> [Misc] -> Document i
Document (Maybe XMLDecl -> [Misc] -> Maybe DocTypeDecl -> [Misc] -> Prolog
Prolog (forall a. a -> Maybe a
Just (String -> Maybe EncodingDecl -> Maybe Bool -> XMLDecl
XMLDecl String
"1.0" forall a. Maybe a
Nothing forall a. Maybe a
Nothing))
                     [] (if Bool
dtd then forall a. a -> Maybe a
Just (HType -> DocTypeDecl
toDTD HType
ht) else forall a. Maybe a
Nothing) [])
             forall a. SymTab a
emptyST
             ( case (HType
ht, forall a. XmlContent a => a -> [Content ()]
X.toContents a
value) of
                 (Tuple [HType]
_, [Content ()]
cs)       -> forall i. QName -> [Attribute] -> [Content i] -> Element i
Elem (String -> QName
N forall a b. (a -> b) -> a -> b
$ HType -> ShowS
showHType HType
ht String
"") [] [Content ()]
cs
                 (Defined String
_ [HType]
_ [Constr]
_, [Content ()]
cs) -> forall i. QName -> [Attribute] -> [Content i] -> Element i
Elem (String -> QName
N forall a b. (a -> b) -> a -> b
$ HType -> ShowS
showHType HType
ht String
"-XML") [] [Content ()]
cs
                 (HType
_, [CElem Element ()
e ()])   -> Element ()
e )
             []




type Doc = String
empty :: [Char]
empty :: String
empty = String
""
($$) :: [Char] -> [Char] -> [Char]
$$ :: String -> ShowS
($$) String
a String
b = String
a forall a. [a] -> [a] -> [a]
++ String
"\n" forall a. [a] -> [a] -> [a]
++ String
b
vcat :: [[Char]] -> [Char]
vcat :: [String] -> String
vcat [String]
a = forall (t :: * -> *) a b.
Foldable t =>
(a -> b -> b) -> b -> t a -> b
foldr String -> ShowS
($$) [] [String]
a
hcat :: [[a]] -> [a]
hcat :: forall a. [[a]] -> [a]
hcat = forall (t :: * -> *) a. Foldable t => t [a] -> [a]
concat
(<>) :: [a] -> [a] -> [a]
<> :: forall a. [a] -> [a] -> [a]
(<>) = forall a. [a] -> [a] -> [a]
(++)
(<+>) :: [Char] -> [Char] -> [Char]
<+> :: String -> ShowS
(<+>) String
a String
b = String
a forall a. [a] -> [a] -> [a]
++ String
" " forall a. [a] -> [a] -> [a]
++ String
b
fsep :: [[Char]] -> [Char]
fsep :: [String] -> String
fsep = [String] -> String
vcat
text :: t -> t
text :: forall t. t -> t
text t
string = t
string
parens :: [Char] -> [Char]
parens :: ShowS
parens String
string = String
"("forall a. [a] -> [a] -> [a]
++String
stringforall a. [a] -> [a] -> [a]
++String
")"
nest :: t -> t1 -> t1
nest :: forall t t1. t -> t1 -> t1
nest t
_ t1
string = t1
string



either :: (t -> t1) -> (t2 -> t1) -> Either t t2 -> t1
either :: forall t t1 t2. (t -> t1) -> (t2 -> t1) -> Either t t2 -> t1
either t -> t1
f t2 -> t1
_ (Left t
x)  = t -> t1
f t
x
either t -> t1
_ t2 -> t1
g (Right t2
x) = t2 -> t1
g t2
x

maybe :: (t -> [Char]) -> Maybe t -> [Char]
maybe :: forall t. (t -> String) -> Maybe t -> String
maybe t -> String
_ Maybe t
Nothing  = String
empty
maybe t -> String
f (Just t
x) = t -> String
f t
x

--peref p   = text "%" <> text p <> text ";"

----

document :: Document i -> Doc
prolog   :: Prolog -> Doc
xmldecl  :: XMLDecl -> Doc
misc     :: Misc -> Doc
sddecl   :: Bool -> Doc

doctypedecl :: DocTypeDecl -> Doc
markupdecl  :: MarkupDecl -> Doc
-- extsubset   :: ExtSubset -> Doc
-- extsubsetdecl :: ExtSubsetDecl -> Doc
cp          :: CP -> Doc

element   :: Element i -> Doc
attribute :: Attribute -> Doc                     --etc
content   :: Content i -> Doc

----

document :: forall i. Document i -> String
document (Document Prolog
p SymTab EntityDef
_ Element i
e [Misc]
m)= Prolog -> String
prolog Prolog
p String -> ShowS
$$ forall i. Element i -> String
element Element i
e String -> ShowS
$$ [String] -> String
vcat (forall a b. (a -> b) -> [a] -> [b]
map Misc -> String
misc [Misc]
m)
prolog :: Prolog -> String
prolog (Prolog Maybe XMLDecl
x [Misc]
m1 Maybe DocTypeDecl
dtd [Misc]
m2)= forall t. (t -> String) -> Maybe t -> String
maybe XMLDecl -> String
xmldecl Maybe XMLDecl
x String -> ShowS
$$
                             [String] -> String
vcat (forall a b. (a -> b) -> [a] -> [b]
map Misc -> String
misc [Misc]
m1) String -> ShowS
$$
                             forall t. (t -> String) -> Maybe t -> String
maybe DocTypeDecl -> String
doctypedecl Maybe DocTypeDecl
dtd String -> ShowS
$$
                             [String] -> String
vcat (forall a b. (a -> b) -> [a] -> [b]
map Misc -> String
misc [Misc]
m2)
xmldecl :: XMLDecl -> String
xmldecl (XMLDecl String
v Maybe EncodingDecl
e Maybe Bool
sd)   = forall t. t -> t
text String
"<?xml version='" forall a. [a] -> [a] -> [a]
<> forall t. t -> t
text String
v forall a. [a] -> [a] -> [a]
<> forall t. t -> t
text String
"'" String -> ShowS
<+>
                             forall t. (t -> String) -> Maybe t -> String
maybe EncodingDecl -> String
encodingdecl Maybe EncodingDecl
e String -> ShowS
<+>
                             forall t. (t -> String) -> Maybe t -> String
maybe Bool -> String
sddecl Maybe Bool
sd String -> ShowS
<+>
                             forall t. t -> t
text String
"?>"
misc :: Misc -> String
misc (Comment String
s)           = forall t. t -> t
text String
"<!--" String -> ShowS
<+> forall t. t -> t
text String
s String -> ShowS
<+> forall t. t -> t
text String
"-->"
misc (PI (String
n,String
s))            = forall t. t -> t
text String
"<?" forall a. [a] -> [a] -> [a]
<> forall t. t -> t
text String
n String -> ShowS
<+> forall t. t -> t
text String
s String -> ShowS
<+> forall t. t -> t
text String
"?>"
sddecl :: Bool -> String
sddecl Bool
sd   | Bool
sd           = forall t. t -> t
text String
"standalone='yes'"
            | Bool
otherwise    = forall t. t -> t
text String
"standalone='no'"
doctypedecl :: DocTypeDecl -> String
doctypedecl (DTD QName
n Maybe ExternalID
eid [MarkupDecl]
ds) = if forall (t :: * -> *) a. Foldable t => t a -> Bool
null [MarkupDecl]
ds then
                                  String
hd forall a. [a] -> [a] -> [a]
<> forall t. t -> t
text String
">"
                             else String
hd String -> ShowS
<+> forall t. t -> t
text String
" [" String -> ShowS
$$
                                  [String] -> String
vcat (forall a b. (a -> b) -> [a] -> [b]
map MarkupDecl -> String
markupdecl [MarkupDecl]
ds) String -> ShowS
$$ forall t. t -> t
text String
"]>"
                           where hd :: String
hd = forall t. t -> t
text String
"<!DOCTYPE" String -> ShowS
<+> QName -> String
qname QName
n String -> ShowS
<+>
                                      forall t. (t -> String) -> Maybe t -> String
maybe ExternalID -> String
externalid Maybe ExternalID
eid
markupdecl :: MarkupDecl -> String
markupdecl (Element ElementDecl
e)     = ElementDecl -> String
elementdecl ElementDecl
e
markupdecl (AttList AttListDecl
a)     = AttListDecl -> String
attlistdecl AttListDecl
a
markupdecl (Entity EntityDecl
e)      = EntityDecl -> String
entitydecl EntityDecl
e
markupdecl (Notation NotationDecl
n)    = NotationDecl -> String
notationdecl NotationDecl
n
markupdecl (MarkupMisc Misc
m)  = Misc -> String
misc Misc
m
--markupdecl (MarkupPE p m)  = peref p
-- _ (ExtSubset t ds) = maybe textdecl t $$
--                              vcat (map extsubsetdecl ds)
-- _ (ExtMarkupDecl m)      = markupdecl m
-- extsubsetdecl (ExtConditionalSect c) = conditionalsect c
--extsubsetdecl (ExtPEReference p e)   = peref p

element :: forall i. Element i -> String
element (Elem QName
n [Attribute]
as []) = forall t. t -> t
text String
"<" forall a. [a] -> [a] -> [a]
<> QName -> String
qname QName
n String -> ShowS
<+>
                         [String] -> String
fsep (forall a b. (a -> b) -> [a] -> [b]
map Attribute -> String
attribute [Attribute]
as) forall a. [a] -> [a] -> [a]
<> forall t. t -> t
text String
"/>"
element e :: Element i
e@(Elem QName
n [Attribute]
as [Content i]
cs)
--  | any isText cs    = text "<" <> qname n <+> fsep (map attribute as) <>
--                       text ">" <> hcat (map content cs) <>
--                       text "</" <> qname n <> text ">"
    | forall t. Content t -> Bool
isText (forall a. [a] -> a
head [Content i]
cs) = forall t. t -> t
text String
"<" forall a. [a] -> [a] -> [a]
<> QName -> String
qname QName
n String -> ShowS
<+> [String] -> String
fsep (forall a b. (a -> b) -> [a] -> [b]
map Attribute -> String
attribute [Attribute]
as) forall a. [a] -> [a] -> [a]
<>
                         forall t. t -> t
text String
">" forall a. [a] -> [a] -> [a]
<> forall a. [[a]] -> [a]
hcat (forall a b. (a -> b) -> [a] -> [b]
map forall i. Content i -> String
content [Content i]
cs) forall a. [a] -> [a] -> [a]
<>
                         forall t. t -> t
text String
"</" forall a. [a] -> [a] -> [a]
<> QName -> String
qname QName
n forall a. [a] -> [a] -> [a]
<> forall t. t -> t
text String
">"
    | Bool
otherwise        = let (String
d,String
c) = forall t. Element t -> String -> (String, String)
carryelem Element i
e String
empty
                         in String
d forall a. [a] -> [a] -> [a]
<> String
c

isText :: Content t -> Bool
isText :: forall t. Content t -> Bool
isText (CString Bool
_ String
_ t
_) = Bool
True
isText (CRef Reference
_ t
_)      = Bool
True
isText Content t
_               = Bool
False

carryelem :: forall t. Element t -> String -> (String, String)
carryelem (Elem QName
n [Attribute]
as []) String
c
                       = ( String
c forall a. [a] -> [a] -> [a]
<>
                           forall t. t -> t
text String
"<" forall a. [a] -> [a] -> [a]
<> QName -> String
qname QName
n String -> ShowS
<+> [String] -> String
fsep (forall a b. (a -> b) -> [a] -> [b]
map Attribute -> String
attribute [Attribute]
as)
                         , forall t. t -> t
text String
"/>")
carryelem (Elem QName
n [Attribute]
as [Content t]
cs) String
c
{-  | any isText cs    =  ( c <> element e, empty)
    | otherwise -}     =  let ([String]
cs0,String
d0) = forall a c b. (a -> c -> (b, c)) -> [a] -> c -> ([b], c)
carryscan forall t. Content t -> String -> (String, String)
carrycontent [Content t]
cs (forall t. t -> t
text String
">")
                          in
                          ( String
c forall a. [a] -> [a] -> [a]
<>
                            forall t. t -> t
text String
"<" forall a. [a] -> [a] -> [a]
<> QName -> String
qname QName
n String -> ShowS
<+> [String] -> String
fsep (forall a b. (a -> b) -> [a] -> [b]
map Attribute -> String
attribute [Attribute]
as) String -> ShowS
$$
                            forall t t1. t -> t1 -> t1
nest (CharRef
2 :: Int) ([String] -> String
vcat [String]
cs0) forall a. [a] -> [a] -> [a]
<> --- $$
                            String
d0 forall a. [a] -> [a] -> [a]
<> forall t. t -> t
text String
"</" forall a. [a] -> [a] -> [a]
<> QName -> String
qname QName
n
                          , forall t. t -> t
text String
">")
carrycontent :: Content t -> [Char] -> ([Char], [Char])
carryelem :: Element t -> [Char] -> ([Char], [Char])
carrycontent :: forall t. Content t -> String -> (String, String)
carrycontent (CElem Element t
e t
_) String
c   = forall t. Element t -> String -> (String, String)
carryelem Element t
e String
c
carrycontent (CString Bool
False String
s t
_) String
c = (String
c forall a. [a] -> [a] -> [a]
<> forall t. t -> t
chardata String
s, String
empty)
carrycontent (CString Bool
True  String
s t
_) String
c = (String
c forall a. [a] -> [a] -> [a]
<> ShowS
cdsect String
s, String
empty)
carrycontent (CRef Reference
r t
_) String
c    = (String
c forall a. [a] -> [a] -> [a]
<> Reference -> String
reference Reference
r, String
empty)
carrycontent (CMisc Misc
m t
_) String
c   = (String
c forall a. [a] -> [a] -> [a]
<> Misc -> String
misc Misc
m, String
empty)

carryscan :: (a->c->(b,c)) -> [a] -> c -> ([b],c)
carryscan :: forall a c b. (a -> c -> (b, c)) -> [a] -> c -> ([b], c)
carryscan a -> c -> (b, c)
_ []     c
c = ([],c
c)
carryscan a -> c -> (b, c)
f (a
a:[a]
as) c
c = let (b
b, c
c0) = a -> c -> (b, c)
f a
a c
c
                           ([b]
bs,c
c1) = forall a c b. (a -> c -> (b, c)) -> [a] -> c -> ([b], c)
carryscan a -> c -> (b, c)
f [a]
as c
c0
                       in (b
bforall a. a -> [a] -> [a]
:[b]
bs, c
c1)

--carryelem e@(Elem n as cs) c
--  | isText (head cs) =
--        ( start <>
--          text ">" <> hcat (map content cs) <> text "</" <> text n
--        , text ">")
--  | otherwise =
--        let (d,c0) = foldl carrycontent (start, text ">") cs in
--        ( d <> c0 <> text "</" <> text n
--        , text ">")
--  where start = c <> text "<" <> text n <+> fsep (map attribute as)
--
--carrycontent (d,c) (CElem e)   = let (d',c') = carryelem e c in
--                                 (d $$ nest 2 d',       c')
--carrycontent (d,c) (CString _ s) = (d <> c <> chardata s, empty)
--carrycontent (d,c) (CRef r)    = (d <> c <> reference r,empty)
--carrycontent (d,c) (CMisc m)   = (d $$ c <> misc m,     empty)


attribute :: Attribute -> String
attribute (QName
n,AttValue
v)             = QName -> String
qname QName
n forall a. [a] -> [a] -> [a]
<> forall t. t -> t
text String
"=" forall a. [a] -> [a] -> [a]
<> AttValue -> String
attvalue AttValue
v
content :: forall i. Content i -> String
content (CElem Element i
e i
_)         = forall i. Element i -> String
element Element i
e
content (CString Bool
False String
s i
_) = forall t. t -> t
chardata String
s
content (CString Bool
True String
s i
_)  = ShowS
cdsect String
s
content (CRef Reference
r i
_)          = Reference -> String
reference Reference
r
content (CMisc Misc
m i
_)         = Misc -> String
misc Misc
m

elementdecl :: ElementDecl -> [Char]
elementdecl :: ElementDecl -> String
elementdecl (ElementDecl QName
n ContentSpec
cs) = forall t. t -> t
text String
"<!ELEMENT" String -> ShowS
<+> QName -> String
qname QName
n String -> ShowS
<+>
                                 ContentSpec -> String
contentspec ContentSpec
cs forall a. [a] -> [a] -> [a]
<> forall t. t -> t
text String
">"
contentspec :: ContentSpec -> [Char]
contentspec :: ContentSpec -> String
contentspec ContentSpec
EMPTY              = forall t. t -> t
text String
"EMPTY"
contentspec ContentSpec
ANY                = forall t. t -> t
text String
"ANY"
contentspec (Mixed Mixed
m)          = Mixed -> String
mixed Mixed
m
contentspec (ContentSpec CP
c)    = CP -> String
cp CP
c
--contentspec (ContentPE p cs)   = peref p
cp :: CP -> String
cp (TagName QName
n Modifier
m)       = QName -> String
qname QName
n forall a. [a] -> [a] -> [a]
<> Modifier -> String
modifier Modifier
m
cp (Choice [CP]
cs Modifier
m)       = ShowS
parens (forall a. [[a]] -> [a]
hcat (forall a. a -> [a] -> [a]
intersperse (forall t. t -> t
text String
"|") (forall a b. (a -> b) -> [a] -> [b]
map CP -> String
cp [CP]
cs))) forall a. [a] -> [a] -> [a]
<>
                           Modifier -> String
modifier Modifier
m
cp (Seq [CP]
cs Modifier
m)          = ShowS
parens (forall a. [[a]] -> [a]
hcat (forall a. a -> [a] -> [a]
intersperse (forall t. t -> t
text String
",") (forall a b. (a -> b) -> [a] -> [b]
map CP -> String
cp [CP]
cs))) forall a. [a] -> [a] -> [a]
<>
                           Modifier -> String
modifier Modifier
m
--cp (CPPE p c)          = peref p
modifier :: Modifier -> [Char]
modifier :: Modifier -> String
modifier Modifier
None          = String
empty
modifier Modifier
Query         = forall t. t -> t
text String
"?"
modifier Modifier
Star          = forall t. t -> t
text String
"*"
modifier Modifier
Plus          = forall t. t -> t
text String
"+"
mixed :: Mixed -> [Char]
mixed :: Mixed -> String
mixed  Mixed
PCDATA          = forall t. t -> t
text String
"(#PCDATA)"
mixed (PCDATAplus [QName]
ns)  = forall t. t -> t
text String
"(#PCDATA |" String -> ShowS
<+>
                         forall a. [[a]] -> [a]
hcat (forall a. a -> [a] -> [a]
intersperse (forall t. t -> t
text String
"|") (forall a b. (a -> b) -> [a] -> [b]
map QName -> String
qname [QName]
ns)) forall a. [a] -> [a] -> [a]
<>
                         forall t. t -> t
text String
")*"

attlistdecl :: AttListDecl -> [Char]
attlistdecl :: AttListDecl -> String
attlistdecl (AttListDecl QName
n [AttDef]
ds) = forall t. t -> t
text String
"<!ATTLIST" String -> ShowS
<+> QName -> String
qname QName
n String -> ShowS
<+>
                                 [String] -> String
fsep (forall a b. (a -> b) -> [a] -> [b]
map AttDef -> String
attdef [AttDef]
ds) forall a. [a] -> [a] -> [a]
<> forall t. t -> t
text String
">"
attdef :: AttDef -> [Char]
attdef :: AttDef -> String
attdef (AttDef QName
n AttType
t DefaultDecl
d)          = QName -> String
qname QName
n String -> ShowS
<+> AttType -> String
atttype AttType
t String -> ShowS
<+> DefaultDecl -> String
defaultdecl DefaultDecl
d
atttype :: AttType -> [Char]
atttype :: AttType -> String
atttype  AttType
StringType            = forall t. t -> t
text String
"CDATA"
atttype (TokenizedType TokenizedType
t)      = TokenizedType -> String
tokenizedtype TokenizedType
t
atttype (EnumeratedType EnumeratedType
t)     = EnumeratedType -> String
enumeratedtype EnumeratedType
t
tokenizedtype :: TokenizedType -> [Char]
tokenizedtype :: TokenizedType -> String
tokenizedtype TokenizedType
ID               = forall t. t -> t
text String
"ID"
tokenizedtype TokenizedType
IDREF            = forall t. t -> t
text String
"IDREF"
tokenizedtype TokenizedType
IDREFS           = forall t. t -> t
text String
"IDREFS"
tokenizedtype TokenizedType
ENTITY           = forall t. t -> t
text String
"ENTITY"
tokenizedtype TokenizedType
ENTITIES         = forall t. t -> t
text String
"ENTITIES"
tokenizedtype TokenizedType
NMTOKEN          = forall t. t -> t
text String
"NMTOKEN"
tokenizedtype TokenizedType
NMTOKENS         = forall t. t -> t
text String
"NMTOKENS"
enumeratedtype :: EnumeratedType -> [Char]
enumeratedtype :: EnumeratedType -> String
enumeratedtype (NotationType [String]
n)= [String] -> String
notationtype [String]
n
enumeratedtype (Enumeration [String]
e) = [String] -> String
enumeration [String]
e
notationtype :: [[Char]] -> [Char]
notationtype :: [String] -> String
notationtype [String]
ns                = forall t. t -> t
text String
"NOTATION" String -> ShowS
<+>
                                 ShowS
parens (forall a. [[a]] -> [a]
hcat (forall a. a -> [a] -> [a]
intersperse (forall t. t -> t
text String
"|") (forall a b. (a -> b) -> [a] -> [b]
map forall t. t -> t
text [String]
ns)))
enumeration :: [[Char]] -> [Char]
enumeration :: [String] -> String
enumeration [String]
ns                 = ShowS
parens (forall a. [[a]] -> [a]
hcat (forall a. a -> [a] -> [a]
intersperse (forall t. t -> t
text String
"|") (forall a b. (a -> b) -> [a] -> [b]
map forall t. t -> t
nmtoken [String]
ns)))
defaultdecl :: DefaultDecl -> [Char]
defaultdecl :: DefaultDecl -> String
defaultdecl  DefaultDecl
REQUIRED          = forall t. t -> t
text String
"#REQUIRED"
defaultdecl  DefaultDecl
IMPLIED           = forall t. t -> t
text String
"#IMPLIED"
defaultdecl (DefaultTo AttValue
a Maybe FIXED
f)    = forall t. (t -> String) -> Maybe t -> String
maybe (forall a b. a -> b -> a
const (forall t. t -> t
text String
"#FIXED")) Maybe FIXED
f String -> ShowS
<+> AttValue -> String
attvalue AttValue
a
-- _ (IncludeSect i)= text "<![INCLUDE [" <+>
--                                  vcat (map extsubsetdecl i) <+> text "]]>"
-- conditionalsect (IgnoreSect i) = text "<![IGNORE [" <+>
--                                  fsep (map ignoresectcontents i) <+> text "]]>"
-- _ (Ignore)                = empty
-- _ (IgnoreSectContents i is)
--                                = ignore i <+> vcat (map internal is)
--                           where internal (ics,i) = text "<![[" <+>
--                                                    ignoresectcontents ics <+>
--                                                    text "]]>" <+> ignore i
reference :: Reference -> [Char]
reference :: Reference -> String
reference (RefEntity String
er)       = ShowS
entityref String
er
reference (RefChar CharRef
cr)         = forall a. Show a => a -> String
charref CharRef
cr
entityref :: [Char] -> [Char]
entityref :: ShowS
entityref String
n                    = forall t. t -> t
text String
"&" forall a. [a] -> [a] -> [a]
<> forall t. t -> t
text String
n forall a. [a] -> [a] -> [a]
<> forall t. t -> t
text String
";"
charref :: (Show a) => a -> [Char]
charref :: forall a. Show a => a -> String
charref a
c                      = forall t. t -> t
text String
"&#" forall a. [a] -> [a] -> [a]
<> forall t. t -> t
text (forall a. Show a => a -> String
show a
c) forall a. [a] -> [a] -> [a]
<> forall t. t -> t
text String
";"
entitydecl :: EntityDecl -> [Char]
entitydecl :: EntityDecl -> String
entitydecl (EntityGEDecl GEDecl
d)    = GEDecl -> String
gedecl GEDecl
d
entitydecl (EntityPEDecl PEDecl
d)    = PEDecl -> String
pedecl PEDecl
d
gedecl :: GEDecl -> [Char]
gedecl :: GEDecl -> String
gedecl (GEDecl String
n EntityDef
ed)           = forall t. t -> t
text String
"<!ENTITY" String -> ShowS
<+> forall t. t -> t
text String
n String -> ShowS
<+> EntityDef -> String
entitydef EntityDef
ed forall a. [a] -> [a] -> [a]
<>
                                 forall t. t -> t
text String
">"
pedecl :: PEDecl -> [Char]
pedecl :: PEDecl -> String
pedecl (PEDecl String
n PEDef
pd)           = forall t. t -> t
text String
"<!ENTITY %" forall a. [a] -> [a] -> [a]
<> forall t. t -> t
text String
n String -> ShowS
<+> PEDef -> String
pedef PEDef
pd forall a. [a] -> [a] -> [a]
<>
                                 forall t. t -> t
text String
">"
entitydef :: EntityDef -> [Char]
entitydef :: EntityDef -> String
entitydef (DefEntityValue EntityValue
ew)  = EntityValue -> String
entityvalue EntityValue
ew
entitydef (DefExternalID ExternalID
i Maybe NDataDecl
nd) = ExternalID -> String
externalid ExternalID
i String -> ShowS
<+> forall t. (t -> String) -> Maybe t -> String
maybe NDataDecl -> String
ndatadecl Maybe NDataDecl
nd
pedef :: PEDef -> [Char]
pedef :: PEDef -> String
pedef (PEDefEntityValue EntityValue
ew)    = EntityValue -> String
entityvalue EntityValue
ew
pedef (PEDefExternalID ExternalID
eid)    = ExternalID -> String
externalid ExternalID
eid
externalid :: ExternalID -> [Char]
externalid :: ExternalID -> String
externalid (SYSTEM SystemLiteral
sl)         = forall t. t -> t
text String
"SYSTEM" String -> ShowS
<+> SystemLiteral -> String
systemliteral SystemLiteral
sl
externalid (PUBLIC PubidLiteral
i SystemLiteral
sl)       = forall t. t -> t
text String
"PUBLIC" String -> ShowS
<+> PubidLiteral -> String
pubidliteral PubidLiteral
i String -> ShowS
<+>
                                 SystemLiteral -> String
systemliteral SystemLiteral
sl
ndatadecl :: NDataDecl -> [Char]
ndatadecl :: NDataDecl -> String
ndatadecl (NDATA String
n)            = forall t. t -> t
text String
"NDATA" String -> ShowS
<+> forall t. t -> t
text String
n
-- _ (TextDecl vi ed)      = text "<?xml" <+> maybe text vi <+>
--                                  encodingdecl ed <> text "?>"
-- _ (ExtParsedEnt t c)= maybe textdecl t <+> content c
-- _ (ExtPE t esd)            = maybe textdecl t <+>
--                                  vcat (map extsubsetdecl esd)
notationdecl :: NotationDecl -> [Char]
notationdecl :: NotationDecl -> String
notationdecl (NOTATION String
n Either ExternalID PublicID
e)    = forall t. t -> t
text String
"<!NOTATION" String -> ShowS
<+> forall t. t -> t
text String
n String -> ShowS
<+>
                                 forall t t1 t2. (t -> t1) -> (t2 -> t1) -> Either t t2 -> t1
either ExternalID -> String
externalid PublicID -> String
publicid Either ExternalID PublicID
e forall a. [a] -> [a] -> [a]
<>
                                 forall t. t -> t
text String
">"
publicid :: PublicID -> [Char]
publicid :: PublicID -> String
publicid (PUBLICID PubidLiteral
p)          = forall t. t -> t
text String
"PUBLICID" String -> ShowS
<+> PubidLiteral -> String
pubidliteral PubidLiteral
p
encodingdecl :: EncodingDecl -> [Char]
encodingdecl :: EncodingDecl -> String
encodingdecl (EncodingDecl String
s)  = forall t. t -> t
text String
"encoding='" forall a. [a] -> [a] -> [a]
<> forall t. t -> t
text String
s forall a. [a] -> [a] -> [a]
<> forall t. t -> t
text String
"'"
nmtoken :: t -> t
nmtoken :: forall t. t -> t
nmtoken t
s                      = forall t. t -> t
text t
s
attvalue :: AttValue -> [Char]
attvalue :: AttValue -> String
attvalue (AttValue [Either String Reference]
esr)        = forall t. t -> t
text String
"\"" forall a. [a] -> [a] -> [a]
<>
                                 forall a. [[a]] -> [a]
hcat (forall a b. (a -> b) -> [a] -> [b]
map (forall t t1 t2. (t -> t1) -> (t2 -> t1) -> Either t t2 -> t1
either forall t. t -> t
text Reference -> String
reference) [Either String Reference]
esr) forall a. [a] -> [a] -> [a]
<>
                                 forall t. t -> t
text String
"\""
entityvalue :: EntityValue -> [Char]
entityvalue :: EntityValue -> String
entityvalue (EntityValue [EV]
evs)
  | [EV] -> Bool
containsDoubleQuote [EV]
evs    = forall t. t -> t
text String
"'"  forall a. [a] -> [a] -> [a]
<> forall a. [[a]] -> [a]
hcat (forall a b. (a -> b) -> [a] -> [b]
map EV -> String
ev [EV]
evs) forall a. [a] -> [a] -> [a]
<> forall t. t -> t
text String
"'"
  | Bool
otherwise                  = forall t. t -> t
text String
"\"" forall a. [a] -> [a] -> [a]
<> forall a. [[a]] -> [a]
hcat (forall a b. (a -> b) -> [a] -> [b]
map EV -> String
ev [EV]
evs) forall a. [a] -> [a] -> [a]
<> forall t. t -> t
text String
"\""
ev :: EV -> String
ev :: EV -> String
ev (EVString String
s)                = forall t. t -> t
text String
s
--ev (EVPERef p e)               = peref p
ev (EVRef Reference
r)                   = Reference -> String
reference Reference
r
pubidliteral :: PubidLiteral -> [Char]
pubidliteral :: PubidLiteral -> String
pubidliteral (PubidLiteral String
s)
    | Char
'"' forall (t :: * -> *) a. (Foldable t, Eq a) => a -> t a -> Bool
`elem` String
s             = forall t. t -> t
text String
"'" forall a. [a] -> [a] -> [a]
<> forall t. t -> t
text String
s forall a. [a] -> [a] -> [a]
<> forall t. t -> t
text String
"'"
    | Bool
otherwise                = forall t. t -> t
text String
"\"" forall a. [a] -> [a] -> [a]
<> forall t. t -> t
text String
s forall a. [a] -> [a] -> [a]
<> forall t. t -> t
text String
"\""
systemliteral :: SystemLiteral -> [Char]
systemliteral :: SystemLiteral -> String
systemliteral (SystemLiteral String
s)
    | Char
'"' forall (t :: * -> *) a. (Foldable t, Eq a) => a -> t a -> Bool
`elem` String
s             = forall t. t -> t
text String
"'" forall a. [a] -> [a] -> [a]
<> forall t. t -> t
text String
s forall a. [a] -> [a] -> [a]
<> forall t. t -> t
text String
"'"
    | Bool
otherwise                = forall t. t -> t
text String
"\"" forall a. [a] -> [a] -> [a]
<> forall t. t -> t
text String
s forall a. [a] -> [a] -> [a]
<> forall t. t -> t
text String
"\""
chardata :: t -> t
chardata :: forall t. t -> t
chardata t
s                     = {-if all isSpace s then empty else-} forall t. t -> t
text t
s
cdsect :: [Char] -> [Char]
cdsect :: ShowS
cdsect String
c                       = forall t. t -> t
text String
"<![CDATA[" forall a. [a] -> [a] -> [a]
<> forall t. t -> t
chardata String
c forall a. [a] -> [a] -> [a]
<> forall t. t -> t
text String
"]]>"

qname :: QName -> String
qname QName
n                        = forall t. t -> t
text (QName -> String
printableName QName
n)

----
containsDoubleQuote :: [EV] -> Bool
containsDoubleQuote :: [EV] -> Bool
containsDoubleQuote [EV]
evs = forall (t :: * -> *) a. Foldable t => (a -> Bool) -> t a -> Bool
any EV -> Bool
csq [EV]
evs
    where csq :: EV -> Bool
csq (EVString String
s) = Char
'"' forall (t :: * -> *) a. (Foldable t, Eq a) => a -> t a -> Bool
`elem` String
s
          csq EV
_            = Bool
False