This module provides combinators for generating XML documents.
As an example, suppose you want to generate the following XML document:
<?xml version="1.0"?> <people> <person age="32">Stefan</person> <person age="4">Judith</person> </people>
Then you could use the following Haskell code:
let people = [("Stefan", "32"), ("Judith", "4")] indoc
defaultDocInfo
$xelem
"people" $xelems
$ map ((name, age) ->xelem
"person" (xattr
"age" age<#>
xtext
name)) people
- data Xml t
- data Doc
- data DocInfo = DocInfo {}
- doc :: DocInfo -> Xml Elem -> Xml Doc
- defaultDocInfo :: DocInfo
- data Namespace
- type Prefix = String
- type Uri = String
- namespace :: Prefix -> Uri -> Namespace
- noNamespace :: Namespace
- defaultNamespace :: Namespace
- data Elem
- class AddChildren c => MkElem n c where
- xelem :: n -> MkElemRes n c
- class MkEmptyElem n where
- xelemEmpty :: n -> MkEmptyElemRes n
- class AddChildren c
- xelems :: [Xml Elem] -> Xml Elem
- noElems :: Xml Elem
- xelemWithText :: TextContent t => String -> t -> Xml Elem
- (<>) :: Monoid t => t -> t -> t
- (<#>) :: a -> b -> (a, b)
- data Attr
- class MkAttr n t where
- xattr :: TextContent t => n -> MkAttrRes n t
- xattrRaw :: RawTextContent t => n -> MkAttrRes n t
- xattrs :: [Xml Attr] -> Xml Attr
- noAttrs :: Xml Attr
- class RawTextContent t
- class RawTextContent t => TextContent t
- xtext :: TextContent t => t -> Xml Elem
- xtextRaw :: RawTextContent t => t -> Xml Elem
- xentityRef :: String -> Xml Elem
- xempty :: Renderable t => Xml t
- class Renderable t => Misc t where
- xrender :: (Renderable r, XmlOutput t) => Xml r -> t
- class XmlOutput t where
- fromBuilder :: Builder -> t
- class Renderable t
- xhtmlFramesetDocInfo :: DocInfo
- xhtmlStrictDocInfo :: DocInfo
- xhtmlTransitionalDocInfo :: DocInfo
- xhtmlRootElem :: String -> Xml Elem -> Xml Elem
General
Documents
The DocInfo
type contains all information of an XML document except the root element.
DocInfo | |
|
doc :: DocInfo -> Xml Elem -> Xml DocSource
Constructs an XML document from a DocInfo
value and the root element.
defaultDocInfo :: DocInfoSource
The default document info (standalone, without document type, without content before/after the root element).
Namespaces
Type for representing presence or absence of an XML namespace.
namespace :: Prefix -> Uri -> NamespaceSource
Constructs a qualified XML namespace. The given URI must not be the empty string.
noNamespace :: NamespaceSource
A Namespace
value denoting the absence of any XML namespace information.
defaultNamespace :: NamespaceSource
A Namespace
value denoting the default namespace.
- For elements, this is the namespace currently mapped to the empty prefix.
- For attributes, the default namespace does not carry any namespace information.
Elements
A piece of XML at the element level.
Renderable Elem | |
Misc Elem | |
Monoid (Xml Elem) | |
AddChildren (Xml Elem) | |
AddChildren (Xml Attr, Xml Elem) |
class AddChildren c => MkElem n c whereSource
Class providing methods for constructing XML elements.
The String
instance of this class constructs an element in the
default namespace, the Namespace
instance allows customization of
namespaces.
AddChildren c => MkElem String c | |
AddChildren c => MkElem Namespace c |
class MkEmptyElem n whereSource
Class providing a method for constructing XML elements without children.
The String
instance of this class constructs an element in the
default namespace, the Namespace
instance allows customization of
namespaces.
xelemEmpty :: n -> MkEmptyElemRes nSource
class AddChildren c Source
Class for adding children to an element.
The various instances of this class allow the addition of different kinds of children.
AddChildren () | |
TextContent t => AddChildren t | |
AddChildren (Xml Attr) | |
AddChildren (Xml Elem) | |
AddChildren (Xml Attr, Xml Elem) |
xelems :: [Xml Elem] -> Xml ElemSource
Merges a list of elements into a single piece of XML at the element level.
xelemWithText :: TextContent t => String -> t -> Xml ElemSource
The expression xelemWithText n t
constructs an XML element with name n
and text content t
.
(<>) :: Monoid t => t -> t -> tSource
Shortcut for the mappend
functions of monoids. Used to concatenate elements, attributes
and text nodes.
(<#>) :: a -> b -> (a, b)Source
Shortcut for coonstructing pairs. Used in combination with xelem
for separating child-attributes
from child-elements.
Attributes
A piece of XML at the attribute level.
Renderable Attr | |
Monoid (Xml Attr) | |
AddChildren (Xml Attr) | |
AddChildren (Xml Attr, Xml Elem) |
Class providing methods for constructing XML attributes.
The String
instance of this class constructs an attribute with a name
in the default namespace, the Namespace
instance allows customization
of namespaces.
xattr :: TextContent t => n -> MkAttrRes n tSource
Construct an attribute by escaping its value
xattrRaw :: RawTextContent t => n -> MkAttrRes n tSource
Construct an attribute without escaping its value. Note: attribute values are quoted with double quotes.
xattrs :: [Xml Attr] -> Xml AttrSource
Merges a list of attributes into a single piece of XML at the attribute level.
Text
class RawTextContent t Source
Construction of text content not subject to escaping.
class RawTextContent t => TextContent t Source
Construction of text content subject to escaping.
xtext :: TextContent t => t -> Xml ElemSource
Constructs a text node by escaping the given argument.
xtextRaw :: RawTextContent t => t -> Xml ElemSource
Constructs a text node without escaping the given argument.
xentityRef :: String -> Xml ElemSource
Constructs a reference to the named entity. Note: no escaping is performed on the name of the entity
Other
xempty :: Renderable t => Xml tSource
An empty, polymorphic piece of XML.
class Renderable t => Misc t whereSource
Class providing methods for adding processing instructions and comments.
xprocessingInstruction :: String -> String -> Xml tSource
Constructs a processing instruction with the given target and content. Note: Rendering does not perform escaping on the target and the content.
xcomment :: String -> Xml tSource
Constructs an XML comment. Note: No escaping is performed on the text of the comment.
Rendering
xrender :: (Renderable r, XmlOutput t) => Xml r -> tSource
Renders a given piece of XML.
Instances of the XmlOutput
class may serve as target of serializing an XML document.
fromBuilder :: Builder -> tSource
Creates the target type from a Builder
.
class Renderable t Source
Any type subject to rendering must implement this type class.
XHTML documents
xhtmlFramesetDocInfo :: DocInfoSource
Document info for XHTML 1.0 frameset.
xhtmlStrictDocInfo :: DocInfoSource
Document info for XHTML 1.0 strict.
xhtmlTransitionalDocInfo :: DocInfoSource
Document info for XHTML 1.0 transitional.