Skip to content

Instantly share code, notes, and snippets.

@seanhess
Created November 8, 2011 02:37
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save seanhess/1346854 to your computer and use it in GitHub Desktop.
Save seanhess/1346854 to your computer and use it in GitHub Desktop.
Lazy SAX parser
-- http://hackage.haskell.org/packages/archive/hexpat/0.19.7/doc/html/Text-XML-Expat-SAX.html#g:2
-- http://stackoverflow.com/questions/2292729/with-haskell-how-do-i-process-large-volumes-of-xml
import qualified Data.ByteString.Lazy as BSL
import Prelude hiding (readFile)
import Text.XML.Expat.SAX
main = do
-- I need a ByteString
contents <- BSL.readFile "schedules.xml"
let events = parse defaultParseOptions contents
print $ map getTMSId $ filter isEvent events
putStrLn "DONE"
isEvent :: SAXEvent String String -> Bool
isEvent (StartElement "event" as) = True
isEvent _ = False
getTMSId :: SAXEvent String String -> Maybe String
getTMSId (StartElement _ as) = lookup "TMSId" as
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment