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

Safe Haskell | None
Language | Haskell2010

Text.XML.Stream.Render.Internal

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 :: forall (m :: Type -> Type). Monad m => RenderSettings -> ConduitT Event Builder m ()
- renderBuilderFlush :: forall (m :: Type -> Type). Monad m => RenderSettings -> ConduitT (Flush Event) (Flush Builder) m ()
- renderBytes :: forall (m :: Type -> Type). PrimMonad m => RenderSettings -> ConduitT Event ByteString m ()
- renderText :: forall (m :: Type -> Type). (PrimMonad m, MonadThrow m) => RenderSettings -> ConduitT Event Text m ()
- 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
- rsXMLDeclaration :: RenderSettings -> Bool
- orderAttrs :: [(Name, [Name])] -> Name -> Map Name Text -> [(Name, Text)]
- document :: forall (m :: Type -> Type) i. Monad m => ConduitT i Event m () -> ConduitT i Event m ()
- tag :: forall (m :: Type -> Type) i. Monad m => Name -> Attributes -> ConduitT i Event m () -> ConduitT i Event m ()
- content :: forall (m :: Type -> Type) i. Monad m => Text -> ConduitT i Event m ()
- data Attributes
- attr :: Name -> Text -> Attributes
- optionalAttr :: Name -> Maybe Text -> Attributes

# Rendering XML files

renderBuilder :: forall (m :: Type -> Type). Monad m => RenderSettings -> ConduitT Event Builder m () Source #

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 :: forall (m :: Type -> Type). Monad m => RenderSettings -> ConduitT (Flush Event) (Flush Builder) m () Source #

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 :: forall (m :: Type -> Type). PrimMonad m => RenderSettings -> ConduitT Event ByteString m () Source #

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.

renderText :: forall (m :: Type -> Type). (PrimMonad m, MonadThrow m) => RenderSettings -> ConduitT Event Text m () Source #

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.

# Renderer settings

data RenderSettings Source #

#### Instances

Instances details

Default RenderSettings Source # |
Instance details Defined in Text.XML.Stream.Render.Internal Methods def :: RenderSettings Source #

def :: Default a => a Source #

The default value for this type.

rsPretty :: RenderSettings -> Bool Source #

Pretty-print XML document. Implementation is arbitrary and can change the meaning of your XML (e.g. by adding whitespace and newlines in text content.)

See https://github.com/snoyberg/xml/issues/196.

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

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)] Source #

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

rsUseCDATA :: RenderSettings -> Content -> Bool Source #

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

Default: `False`

Since: 1.3.3

rsXMLDeclaration :: RenderSettings -> Bool Source #

Determines whether the XML declaration will be output. Note that when using the streaming API the XML declaration will be output only if this is set to true and the stream includes an `EventBeginDocument` event. Apart from yielding it explicitly, this can be achieved by wrapping the stream in the `document` function.

Default: `True`

Since: 1.5.1

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

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

document :: forall (m :: Type -> Type) i. Monad m => ConduitT i Event m () -> ConduitT i Event m () Source #

Wrap the given stream in an `EventBeginDocument`/`EventEndDocument` pair.

Since: 1.10.1.0

tag Source #

Arguments

:: forall (m :: Type -> Type) i. Monad m |
=> Name |
-> Attributes |
-> ConduitT i Event m () | `Element'`s subnodes.
-> ConduitT i Event m () |

Generate a complete XML `Element`.

content :: forall (m :: Type -> Type) i. Monad m => Text -> ConduitT i Event m () Source #

Generate a textual `EventContent`.

# Attribute rendering

data Attributes Source #

A list of attributes.

#### Instances

Instances details

Monoid Attributes Source # |
Instance details Defined in Text.XML.Stream.Render.Internal Methods mempty :: Attributes Source # mappend :: Attributes -> Attributes -> Attributes Source # mconcat :: [Attributes] -> Attributes Source #
Semigroup Attributes Source # |
Instance details Defined in Text.XML.Stream.Render.Internal Methods (<>) :: Attributes -> Attributes -> Attributes Source # sconcat :: NonEmpty Attributes -> Attributes Source # stimes :: Integral b => b -> Attributes -> Attributes Source #

attr Source #

Arguments

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

Generate a single attribute.

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

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