xmlgen-0.6.2.0: Fast XML generation library

Safe HaskellNone

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 = TextSource

Namespace prefix.

type Uri = TextSource

Namespace URI.

type Name = TextSource

A type for names

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.

xelem :: AddChildren c => Name -> c -> Xml ElemSource

Construct a simple-named element with the given children.

xelemQ :: AddChildren c => Namespace -> Name -> c -> Xml ElemSource

Construct an element with the given children.

xelemEmpty :: Name -> Xml ElemSource

Construct a simple-named element without any children.

xelemQEmpty :: Namespace -> Name -> Xml ElemSource

Construct an element without any children.

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 :: Name -> TextContent -> Xml ElemSource

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

(<>) :: Monoid m => m -> m -> m

An infix synonym for mappend.

(<#>) :: a -> b -> (a, b)Source

Shortcut for constructing 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.

xattr :: Name -> TextContent -> Xml AttrSource

Construct a simple-named attribute by escaping its value.

xattrQ :: Namespace -> Name -> TextContent -> Xml AttrSource

Construct an attribute by escaping its value.

xattrQRaw :: Namespace -> Name -> Builder -> Xml AttrSource

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

xattrs :: [Xml Attr] -> Xml AttrSource

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

noAttrs :: Xml AttrSource

The empty attribute list.

Text

type TextContent = TextSource

Text content subject to escaping.

xtext :: TextContent -> Xml ElemSource

Constructs a text node by escaping the given argument.

xtextRaw :: Builder -> Xml ElemSource

Constructs a text node without escaping the given argument.

xentityRef :: Name -> 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 :: Text -> Xml Elem -> Xml ElemSource

Constructs the root element of an XHTML document.