Skip to content

Instantly share code, notes, and snippets.

@danchoi
Last active June 27, 2019 20:02
Show Gist options
  • Save danchoi/8fe92ede21249ed305f0dadf374fd034 to your computer and use it in GitHub Desktop.
Save danchoi/8fe92ede21249ed305f0dadf374fd034 to your computer and use it in GitHub Desktop.
Show all XML tags
#!/usr/bin/env stack
-- stack --resolver lts-12.21 script --package hexpat --package bytestring --package text
{-
dependency: install libexpat1-dev
sudo apt install libexpat1-dev
Pipe in the XML input, outputs a list of tag names as it encounters them. Use unix
tools `sort` and `uniq -c` to tally the tag frequency.
-}
{-# LANGUAGE ScopedTypeVariables #-}
import qualified Data.ByteString.Lazy.Char8 as BL8
import Data.Text (Text)
import qualified Data.Text.IO as T
import Text.XML.Expat.SAX
main :: IO ()
main = do
lbs <- BL8.getContents
mapM_ T.putStrLn $ [ t | (StartElement t _) :: SAXEvent Text Text <- parse (ParseOptions Nothing Nothing) lbs ]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment