xmlgen-0.6.2.1: Fast XML generation library

Safe HaskellNone
LanguageHaskell2010

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 #

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

Instances

Monoid (Xml Attr) # 
Monoid (Xml Elem) # 
AddChildren (Xml Attr) # 

Methods

addChildren :: Xml Attr -> NsEnv -> Builder

AddChildren (Xml Elem) # 

Methods

addChildren :: Xml Elem -> NsEnv -> Builder

AddChildren (Xml Attr, [Xml Elem]) # 

Methods

addChildren :: (Xml Attr, [Xml Elem]) -> NsEnv -> Builder

AddChildren (Xml Attr, Xml Elem) # 

Methods

addChildren :: (Xml Attr, Xml Elem) -> NsEnv -> Builder

Documents

data Doc #

A piece of XML at the document level.

data DocInfo #

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

Constructors

DocInfo 

Fields

doc :: DocInfo -> Xml Elem -> Xml Doc #

Constructs an XML document from a DocInfo value and the root element.

defaultDocInfo :: DocInfo #

The default document info (standalone, without document type, without content before/after the root element).

Namespaces

data Namespace #

Type for representing presence or absence of an XML namespace.

type Prefix = Text #

Namespace prefix.

type Uri = Text #

Namespace URI.

type Name = Text #

A type for names

namespace :: Prefix -> Uri -> Namespace #

Constructs a qualified XML namespace. The given URI must not be the empty string.

noNamespace :: Namespace #

A Namespace value denoting the absence of any XML namespace information.

defaultNamespace :: Namespace #

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 #

A piece of XML at the element level.

xelem :: AddChildren c => Name -> c -> Xml Elem #

Construct a simple-named element with the given children.

xelemQ :: AddChildren c => Namespace -> Name -> c -> Xml Elem #

Construct an element with the given children.

xelemEmpty :: Name -> Xml Elem #

Construct a simple-named element without any children.

xelemQEmpty :: Namespace -> Name -> Xml Elem #

Construct an element without any children.

class AddChildren c #

Class for adding children to an element.

The various instances of this class allow the addition of different kinds of children.

Minimal complete definition

addChildren

Instances

AddChildren () # 

Methods

addChildren :: () -> NsEnv -> Builder

AddChildren String # 

Methods

addChildren :: String -> NsEnv -> Builder

AddChildren TextContent # 

Methods

addChildren :: TextContent -> NsEnv -> Builder

AddChildren (Xml Attr) # 

Methods

addChildren :: Xml Attr -> NsEnv -> Builder

AddChildren (Xml Elem) # 

Methods

addChildren :: Xml Elem -> NsEnv -> Builder

AddChildren (Xml Attr, [Xml Elem]) # 

Methods

addChildren :: (Xml Attr, [Xml Elem]) -> NsEnv -> Builder

AddChildren (Xml Attr, Xml Elem) # 

Methods

addChildren :: (Xml Attr, Xml Elem) -> NsEnv -> Builder

xelems :: [Xml Elem] -> Xml Elem #

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

noElems :: Xml Elem #

No elements at all.

xelemWithText :: Name -> TextContent -> Xml Elem #

The expression xelemWithText n t constructs an XML element with name n and text content t.

(<>) :: Monoid m => m -> m -> m infixr 6 #

An infix synonym for mappend.

Since: 4.5.0.0

(<#>) :: a -> b -> (a, b) infixl 5 #

Shortcut for constructing pairs. Used in combination with xelem for separating child-attributes from child-elements.

Attributes

data Attr #

A piece of XML at the attribute level.

Instances

Renderable Attr # 
Monoid (Xml Attr) # 
AddChildren (Xml Attr) # 

Methods

addChildren :: Xml Attr -> NsEnv -> Builder

AddChildren (Xml Attr, [Xml Elem]) # 

Methods

addChildren :: (Xml Attr, [Xml Elem]) -> NsEnv -> Builder

AddChildren (Xml Attr, Xml Elem) # 

Methods

addChildren :: (Xml Attr, Xml Elem) -> NsEnv -> Builder

xattr :: Name -> TextContent -> Xml Attr #

Construct a simple-named attribute by escaping its value.

xattrQ :: Namespace -> Name -> TextContent -> Xml Attr #

Construct an attribute by escaping its value.

xattrQRaw :: Namespace -> Name -> Builder -> Xml Attr #

Construct an attribute without escaping its value. Note: attribute values are quoted with double quotes.

xattrs :: [Xml Attr] -> Xml Attr #

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

noAttrs :: Xml Attr #

The empty attribute list.

Text

type TextContent = Text #

Text content subject to escaping.

xtext :: TextContent -> Xml Elem #

Constructs a text node by escaping the given argument.

xtextRaw :: Builder -> Xml Elem #

Constructs a text node without escaping the given argument.

xentityRef :: Name -> Xml Elem #

Constructs a reference to the named entity. Note: no escaping is performed on the name of the entity

Other

xempty :: Renderable t => Xml t #

An empty, polymorphic piece of XML.

class Renderable t => Misc t where #

Class providing methods for adding processing instructions and comments.

Methods

xprocessingInstruction :: String -> String -> Xml t #

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 t #

Constructs an XML comment. Note: No escaping is performed on the text of the comment.

Rendering

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

Renders a given piece of XML.

class XmlOutput t where #

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

Minimal complete definition

fromBuilder

Methods

fromBuilder :: Builder -> t #

Creates the target type from a Builder.

class Renderable t #

Any type subject to rendering must implement this type class.

Minimal complete definition

builder, mkRenderable

XHTML documents

xhtmlFramesetDocInfo :: DocInfo #

Document info for XHTML 1.0 frameset.

xhtmlStrictDocInfo :: DocInfo #

Document info for XHTML 1.0 strict.

xhtmlTransitionalDocInfo :: DocInfo #

Document info for XHTML 1.0 transitional.

xhtmlRootElem :: Text -> Xml Elem -> Xml Elem #

Constructs the root element of an XHTML document.