hexml-lens-0.1.0.0: Lenses for the hexml package

Safe HaskellNone
LanguageHaskell2010

Text.XML.Hexml.Lens

Contents

Synopsis

Nodes

_children :: Fold Node Node Source #

Fold over the element children

_contents :: Fold Node (Either ByteString Node) Source #

Fold over all the children (text and element)

class ChildNode s where Source #

Folds for element nodes

Minimal complete definition

node

Methods

node :: s -> Fold Node Node Source #

Instances

ChildNode Int Source #

A fold for accessing a child node by its index

Methods

node :: Int -> Fold Node Node Source #

ChildNode String Source #

A fold for accessing named children nodes This is a more efficient version of

node foo = _children . filtered (\n -> name n == foo)
ChildNode ByteString Source #

A fold for accessing named children nodes This is a more efficient version of

node foo = _children . filtered (\n -> name n == foo)
ChildNode String Source #

A fold for accessing named children nodes This is a more efficient version of

node foo = _children . filtered (\n -> name n == foo)
ChildNode Text Source #

A fold for accessing named children nodes This is a more efficient version of

node foo = _children . filtered (\n -> name n == foo)

Methods

node :: Text -> Fold Node Node Source #

class TextContents s where Source #

Fold for accessing the text contents of a node

Minimal complete definition

textContents

Attributes

Parsing

class AsXML s where Source #

Methods

_XML :: Prism' s Node Source #

A prism for parsing and unparsing XML.

unparsing is provided by outer.

>>> "<?xml version=\"1.0\"?><foo/>" ^? _XML
Just Node "<?xml version=\"1.0\"?><foo/>"

Nameless nodes are inserted for trees with >1 root.

>>> "<?xml version=\"1.0\"?><foo/>" ^? _XML.to name
Just ""
>>> "<?xml version=\"1.0\"?><foo/>" ^? _XML.node(0::Int)
Just Node "<?xml version=\"1.0\"?>"
>>> "<?xml version=\"1.0\"?><foo/>" ^? _XML.node(1::Int)
Just Node "<foo/>"

If the tree has only 1 root, no nameless nodes are inserted.

>>> "<foo/>" ^? _XML.re(_XML @String)._XML.to name
Just "foo"

The law x ^? re _XML . _XML == x doesn't hold for the nameless nodes injected by parse.

>>> parse "<foo/>" ^? _Right.to name
Just ""
>>> parse "<foo/>" ^? _Right.re(_XML @String)._XML.to name
Just "foo"