Copyright | (c) 2015-2023 Fumiaki Kinoshita 2023 Marco Zocca |
---|---|
License | BSD-style |
Maintainer | ocramz |
Stability | experimental |
Portability | portable |
Safe Haskell | Safe-Inferred |
Language | Haskell2010 |
XML (and HTML) DOM selectors for `xml-conduit` based on microlens
.
This library provides combinators for traversing and folding over XML trees. It could be useful for editing trees, adding attributes selectively (e.g. refactoring CSS, adding HTMX attributes etc.)
Some definitions are taken from 'xml-lens' but we import microlens
to achieve
a smaller dependency footprint.
Synopsis
- subtree :: (Text -> Bool) -> (Text -> Text -> Bool) -> Getting r Element (Maybe Element)
- remapAttributes :: (Name -> Map Name Text -> Maybe (Map Name Text)) -> Getting r Element Element
- root :: Lens' Document Element
- prologue :: Lens' Document Prologue
- epilogue :: Lens' Document [Miscellaneous]
- named :: CI Text -> Traversal' Element Element
- nodes :: Lens' Element [Node]
- attrs :: Lens' Element (Map Name Text)
- attributeSatisfies :: Name -> (Text -> Bool) -> Traversal' Element Element
- attributeIs :: Name -> Text -> Traversal' Element Element
- withoutAttribute :: Name -> Traversal' Element Element
Documentation
:: (Text -> Bool) | predicate on element name |
-> (Text -> Text -> Bool) | predicate on attribute name, value |
-> Getting r Element (Maybe Element) |
Extract a DOM subtree whose root element satisfies the given predicates
:: (Name -> Map Name Text -> Maybe (Map Name Text)) | element name, element attributes |
-> Getting r Element Element |
Remap all attributes. Handy for editing HREF or SRC targets, adding HTMX attributes to certain elements only, etc.
If the callback returns Nothing, the element attributes are left unchanged
From 'xml-lens'
epilogue :: Lens' Document [Miscellaneous] Source #
Epilogue, i.e. the last elements, of the Document
named :: CI Text -> Traversal' Element Element Source #
Traverse elements which has the specified *local* name (case-insensitive).
:: Name | attribute name |
-> (Text -> Bool) | predicate on the value of the attribute |
-> Traversal' Element Element |
Traverse over only the elements such that the value of the given attribute satisfy a predicate
:: Name | attribute name |
-> Text | value of the attribute |
-> Traversal' Element Element |
Traverse over only the elements with a given attribute name and value