Created
February 21, 2012 11:56
-
-
Save adbrowne/1876099 to your computer and use it in GitHub Desktop.
Haskell HaXml Sample of Lazily Reading XML file (in this case badges file from stackoverflow data dump)
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
import Text.XML.HaXml.ParseLazy as PL | |
import Text.XML.HaXml | |
import Text.XML.HaXml.Posn | |
import System.IO | |
main = do | |
inh <- openFile "badges.xml" ReadMode | |
hSetEncoding inh utf8_bom | |
inpStr <- hGetContents inh | |
let (Document _ _ root _) = PL.xmlParse "badges.xml" inpStr | |
let rootElem = CElem root noPos | |
print $ length $ tag "badges" rootElem | |
let rows = tag "badges" /> tag "row" $ rootElem | |
let first = head rows | |
let (CElem (Elem name attributes _)_) = first | |
print name | |
print attributes | |
hClose inh |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment