xmlgen-0.4.0.1: Fast XML generation library

Text.XML.Generator

Contents

Description

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")]
 in doc defaultDocInfo $
      xelem "people" $
        xelems $ map ((name, age) -> xelem "person" (xattr "age" age <#> xtext name)) people

Synopsis

General

data Xml t Source

The type Xml t represent a piece of XML of type t, where t is usually one of Elem, Attr, or Doc.

Documents

data Doc Source

A piece of XML at the document level.

Instances

data DocInfo Source

The DocInfo type contains all information of an XML document except the root element.

Constructors

DocInfo 

Fields

docInfo_standalone :: Bool

Value of the standalone attribute in the <?xml ... ?> header

docInfo_docType :: Maybe String

Document type (N.B.: rendering does not escape this value)

docInfo_preMisc :: Xml Doc

Content before the root element

docInfo_postMisc :: Xml Doc

Content after the root element

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

data Namespace Source

Type for representing presence or absence of an XML namespace.

type Prefix = StringSource

Namespace prefix.

type Uri = StringSource

Namespace URI.

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

data Elem Source

A piece of XML at the element level.

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.

Methods

xelem :: n -> MkElemRes n cSource

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.

Methods

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.

xelems :: [Xml Elem] -> Xml ElemSource

Merges a list of elements into a single piece of XML at the element level.

noElems :: Xml ElemSource

No elements at all.

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

data Attr Source

A piece of XML at the attribute level.

class MkAttr n t whereSource

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.

Methods

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.

Instances

xattrs :: [Xml Attr] -> Xml AttrSource

Merges a list of attributes into a single piece of XML at the attribute level.

noAttrs :: Xml AttrSource

The empty attribute list.

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.

Methods

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.

Instances

Rendering

xrender :: (Renderable r, XmlOutput t) => Xml r -> tSource

Renders a given piece of XML.

class XmlOutput t whereSource

Instances of the XmlOutput class may serve as target of serializing an XML document.

Methods

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.

xhtmlRootElem :: String -> Xml Elem -> Xml ElemSource

Constructs the root element of an XHTML document.