Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/fumieval/xml-lens

Lenses and traversals for xml-conduit
https://github.com/fumieval/xml-lens

Last synced: about 2 months ago
JSON representation

Lenses and traversals for xml-conduit

Awesome Lists containing this project

README

        

xml-lens
========

Lenses and traversals for [xml-conduit](http://hackage.haskell.org/package/xml-conduit).

Example
========

```haskell
> doc <- Text.XML.readFile def "examples/books.xml"

> doc ^.. root . named "books" ... named "book" . attributeIs "category" "Textbooks" ... named "title" . text
["Learn You a Haskell for Great Good!","Programming in Haskell","Real World Haskell"]

> lengthOf ?? doc $ root . named "books" ... named "book"
7

> doc ^? root . named "books" ... attributeIs "category" "Joke" ... named "title" . text
Just "Functional Ikamusume"

> doc & root . named "books" ... named "book" ... named "pages" . text <>~ " pages" & renderLBS def & BL.putStrLn
```

```xml

Haskell 98 language and libraries: the Revised Report
Simon Peyton Jones
272 pages
£45.00

Learn You a Haskell for Great Good!
Miran Lipovaca
360 pages

Programming in Haskell
Graham Hutton
200 pages


```

Tips
----

* Use [cosmos](http://hackage.haskell.org/package/lens-4.19.2/docs/Control-Lens-Plated.html) to traverse over all children
* You can do or-composition of traversals with [failing](http://hackage.haskell.org/package/lens-4.19.2/docs/Control-Lens-Traversal.html#v:failing)