Created
November 8, 2011 02:37
-
-
Save seanhess/1346854 to your computer and use it in GitHub Desktop.
Lazy SAX parser
This file contains hidden or 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
-- 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