Lenses and traversals for xml-conduit
Go to file
2023-07-19 15:56:45 +02:00
.github/workflows update ci 2022-05-15 14:03:05 +09:00
examples add an example 2013-06-18 21:28:58 +09:00
Text/XML Eta expand to allow build on GHC 9 2021-05-12 21:22:30 +03:00
.gitattributes first commit 2013-06-18 21:04:23 +09:00
.gitignore GitHub Actions 2021-01-05 21:49:41 +09:00
cabal.project GitHub Actions 2021-01-05 21:49:41 +09:00
CHANGELOG.md version bump 2022-05-15 14:02:39 +09:00
LICENSE first commit 2013-06-18 21:04:23 +09:00
README.md add Tips 2021-01-06 18:41:26 +09:00
Setup.hs first commit 2013-06-18 21:04:23 +09:00
stack.yaml increase lens bound 2023-07-19 15:56:45 +02:00
xml-lens.cabal increase lens bound 2023-07-19 15:56:45 +02:00

xml-lens

Lenses and traversals for xml-conduit.

Example

> 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 version="1.0" encoding="ISO-8859-1"?>
<books>
<book category="Language and library definition">
    <title>Haskell 98 language and libraries: the Revised Report</title>
    <author year="2003">Simon Peyton Jones</author>
    <pages>272 pages</pages>
    <price>£45.00</price>
</book>
<book category="Textbooks">
    <title>Learn You a Haskell for Great Good!</title>
    <author year="2011">Miran Lipovaca</author>
    <pages>360 pages</pages>
</book>
<book category="Textbooks">
    <title>Programming in Haskell</title>
    <author year="2007">Graham Hutton</author>
    <pages>200 pages</pages>
</book>

Tips

  • Use cosmos to traverse over all children
  • You can do or-composition of traversals with failing