xml-conduit-1.4.0.2: Pure-Haskell utilities for dealing with XML with the conduit package.

Safe Haskell | None
Language | Haskell98

Text.XML.Stream.Render

Contents

- Rendering XML files
- Renderer settings
- Event rendering
- Attribute rendering

Description

`Enumeratee`s to render XML `Event`s. Unlike libxml-enumerator and expat-enumerator, this module does not provide IO and ST variants, since the underlying rendering operations are pure functions.

Synopsis

- renderBuilder :: Monad m => RenderSettings -> Conduit Event m Builder
- renderBuilderFlush :: Monad m => RenderSettings -> Conduit (Flush Event) m (Flush Builder)
- renderBytes :: (PrimMonad base, MonadBase base m) => RenderSettings -> ConduitM Event ByteString m ()
- renderText :: (PrimMonad base, MonadBase base m, MonadThrow m) => RenderSettings -> ConduitM Event Text m ()
- prettify :: Monad m => Conduit (Flush Event) m (Flush Event)
- data RenderSettings
- def :: Default a => a
- rsPretty :: RenderSettings -> Bool
- rsNamespaces :: RenderSettings -> [(Text, Text)]
- rsAttrOrder :: RenderSettings -> Name -> Map Name Text -> [(Name, Text)]
- rsUseCDATA :: RenderSettings -> Content -> Bool
- orderAttrs :: [(Name, [Name])] -> Name -> Map Name Text -> [(Name, Text)]
- tag :: Monad m => Name -> Attributes -> Source m Event -> Source m Event
- content :: Monad m => Text -> Source m Event
- data Attributes
- attr :: Name -> Text -> Attributes
- optionalAttr :: Name -> Maybe Text -> Attributes

# Rendering XML files

renderBuilder :: Monad m => RenderSettings -> Conduit Event m Builder #

Render a stream of `Event`s into a stream of `Builder`s. Builders are from the blaze-builder package, and allow the create of optimally sized `ByteString`s with minimal buffer copying.

renderBuilderFlush :: Monad m => RenderSettings -> Conduit (Flush Event) m (Flush Builder) #

Same as `renderBuilder` but allows you to flush XML stream to ensure that all events at needed point are rendered.

Since: 1.3.5

renderBytes :: (PrimMonad base, MonadBase base m) => RenderSettings -> ConduitM Event ByteString m () #

Render a stream of `Event`s into a stream of `ByteString`s. This function wraps around `renderBuilder` and `builderToByteString`, so it produces optimally sized `ByteString`s with minimal buffer copying.

The output is UTF8 encoded. renderBytes :: Monad m => RenderSettings -> Conduit Event m ByteString

renderText :: (PrimMonad base, MonadBase base m, MonadThrow m) => RenderSettings -> ConduitM Event Text m () #

Render a stream of `Event`s into a stream of `Text`s. This function wraps around `renderBuilder`, `builderToByteString` and `renderBytes`, so it produces optimally sized `Text`s with minimal buffer copying.

prettify :: Monad m => Conduit (Flush Event) m (Flush Event) #

Convert a stream of `Event`s into a prettified one, adding extra whitespace. Note that this can change the meaning of your XML.

# Renderer settings

data RenderSettings #

Instances

Default RenderSettings # |
Methods def :: RenderSettings #

def :: Default a => a #

The default value for this type.

rsPretty :: RenderSettings -> Bool #

rsNamespaces :: RenderSettings -> [(Text, Text)] #

Defines some top level namespace definitions to be used, in the form of (prefix, namespace). This has absolutely no impact on the meaning of your documents, but can increase readability by moving commonly used namespace declarations to the top level.

rsAttrOrder :: RenderSettings -> Name -> Map Name Text -> [(Name, Text)] #

Specify how to turn the unordered attributes used by the Text.XML module into an ordered list.

rsUseCDATA :: RenderSettings -> Content -> Bool #

Determines if for a given text content the renderer should use a CDATA node.

Default: `False`

Since: 1.3.3

orderAttrs :: [(Name, [Name])] -> Name -> Map Name Text -> [(Name, Text)] #

Convenience function to create an ordering function suitable for use as the value of `rsAttrOrder`. The ordering function is created from an explicit ordering of the attributes, specified as a list of tuples, as follows: In each tuple, the first component is the `Name` of an element, and the second component is a list of attributes names. When the given element is rendered, the attributes listed, when present, appear first in the given order, followed by any other attributes in arbitrary order. If an element does not appear, all of its attributes are rendered in arbitrary order.

# Event rendering

tag #

Arguments

:: Monad m |
=> Name |
-> Attributes |
-> Source m Event | `Element'`s subnodes.
-> Source m Event |

Generate a complete XML `Element`.

content :: Monad m => Text -> Source m Event #

Generate a textual `EventContent`.

# Attribute rendering

data Attributes #

A list of attributes.

Instances

Monoid Attributes # |
Methods mempty :: Attributes # mappend :: Attributes -> Attributes -> Attributes # mconcat :: [Attributes] -> Attributes #

attr #

Arguments

:: Name | Attribute's name
-> Text | Attribute's value
-> Attributes |

Generate a single attribute.

optionalAttr :: Name -> Maybe Text -> Attributes #

Helper function that generates a valid attribute if input isn't `Nothing`, or `mempty` otherwise.