HaXml-1.25.5: Utilities for manipulating XML documents

Maintainersimons@cryp.to
Stabilityexperimental
Portabilityportable
Safe HaskellSafe
LanguageHaskell98

Text.XML.HaXml.Verbatim

Description

The preferred method for rendering a Document or single Content is by using the pretty printing facility defined in Pretty. Pretty-printing does not work well for cases, however, where the formatting in the XML document is significant. Examples of this case are XHTML's <pre> tag, Docbook's <literallayout> tag, and many more.

Theoretically, the document author could avoid this problem by wrapping the contents of these tags in a <![CDATA[...]]> section, but often this is not practical, for instance when the literal-layout section contains other elements. Finally, program writers could manually format these elements by transforming them into a literal string in their CFliter, etc., but this is annoying to do and prone to omissions and formatting errors.

As an alternative, this module provides the function verbatim, which will format XML Content as a String while retaining the formatting of the input document unchanged.

Known problems:

  • HaXml's parser eats line feeds between two tags.
  • Attributes should be formatted by making them an instance of Verbatim as well, but since an Attribute is just a tuple, not a full data type, the helper function verbAttr must be used instead.
  • CMisc is not yet supported.
  • MarkupDecls, which contain no content, are formatted as <element-name/>, even if they were not defined as being of type EMPTY. In XML this perfectly alright, but in SGML it is not. Those, who wish to use verbatim to format parts of say an HTML page will have to (a) replace problematic elements by literals before running verbatim or (b) use a second search-and-replace stage to fix this.
Synopsis

Documentation

class Verbatim a where Source #

This class promises that the function verbatim knows how to format this data type into a string without changing the formatting.

Methods

verbatim :: a -> String Source #

Instances
Verbatim Char Source # 
Instance details

Defined in Text.XML.HaXml.Verbatim

Methods

verbatim :: Char -> String Source #

Verbatim AttValue Source # 
Instance details

Defined in Text.XML.HaXml.Verbatim

Verbatim Reference Source # 
Instance details

Defined in Text.XML.HaXml.Verbatim

Verbatim a => Verbatim [a] Source # 
Instance details

Defined in Text.XML.HaXml.Verbatim

Methods

verbatim :: [a] -> String Source #

Verbatim (Content i) Source # 
Instance details

Defined in Text.XML.HaXml.Verbatim

Methods

verbatim :: Content i -> String Source #

Verbatim (Element i) Source # 
Instance details

Defined in Text.XML.HaXml.Verbatim

Methods

verbatim :: Element i -> String Source #

(Verbatim a, Verbatim b) => Verbatim (Either a b) Source # 
Instance details

Defined in Text.XML.HaXml.Verbatim

Methods

verbatim :: Either a b -> String Source #

verbAttr :: Attribute -> String Source #

This is a helper function is required because Haskell does not allow to make an ordinary tuple (like Attribute) an instance of a class. The resulting output will preface the actual attribute with a single blank so that lists of Attributes can be handled implicitly by the definition for lists of Verbatim data types.