Created
December 12, 2017 04:00
-
-
Save tfausak/9ad3612a2f20bfcc4951d0a4ff9153d9 to your computer and use it in GitHub Desktop.
XML lenses have stumped me.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-- stack --resolver nightly-2017-12-01 script | |
{-# LANGUAGE OverloadedStrings #-} | |
import qualified Data.Text.Lazy.IO as LazyText | |
import Text.XML | |
import Text.XML.Lens | |
main :: IO () | |
main = do | |
let original = parseText_ def "<root> <old>1</old> <old>2</old> </root>" | |
let document = original & root ./ named "old" .~ Element "new" mempty [] | |
LazyText.putStrLn $ renderText def { rsXMLDeclaration = False } document | |
-- This prints: | |
-- <root> <new/> <new/> </root> | |
-- But I want: | |
-- <root> <new/> </root> | |
-- This is, *all* <old> elements replaced by a *single* <new> element. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment