7.
XML access in Haskell
import Text. XML as XML xml-- conduit
findElement : : Element —> Name —> [Element]
findElement e name =
[ c
I NodeElement c <- elementNodes e
, e1ementName c = = name ]
getcontent : : Element -> Text
getcontent e =
mconcat [ c I Nodecontent c <- elementNodes e ]
main : : IO ()
main = do
doc <— XML . readFile def "EzoeRyou. rss"
r'ssPr‘int doc
8.
33%
rssPrint : 2 Document —> I0 ()
rssPrint doc = do
let root = documentRoot doc
items = do
chan <— findElement root "channel"
-FindElement chan "item"
-ForM_ items $ ¥item -> do
T. putStrLn $ mconcat $ map getcontent $ findElement item "link"
T. putStrLn $ mconcat :5 map getcontent $ findElement item "title"
T. putStrLn $ mconcat $ map getcontent $ -FindElement item "description"
putStrLn ""
9.
do/ ué: “< Em!
-ADTiEi§2mL‘)§0)iah s”€I3f: %E&>/ utwi
-*l%lC 7r~7lL/ t§’r‘3Dé:73
fi'l%L/ ‘C5’r‘3’Jc‘:73
('-_-‘) lSYB Unipla’re? fl7Zf%3l’LlE, to
: /ur‘— ieo_t57riabx, lei:
JavaScr'pllZl; =v'<5%“ ! J
Text. XML
DOM—based parsing and rendering.
This module requires that all entities be resolved at parsing. If you need
recommended module for most uses cases.
While many of the clatatypes in this module are simply reexpoited from
possibility of unresolved entities. Conversion functions are provided to s
For simpler, bidirectional traversal of the DOM tree, see the Text Xr~’lL Cu
Data types
Us la Document
Constructors
Document
docuiiientlhclague : : Prologue
documentRoot : : Element
documentEpi1ague : : [Miscellaneous]
. », Insta nccs
data Prologue . ~ x
Constructors
Prologue
prologuenefore : : [Miscellaneous]
10.
Text. XML. Cursor
- XPalh5/1”? ??/ i’ ‘/9-7:: —X*635ZalClata‘5§(xm| —conduil)
import Text. XML. Cursor -- also in xml-conduit
rssCursor : : Document -> IO ()
rssCursor doc = do
let items =
fromDocument doc & (element "rss" &/ element "channel" &/ element " item")
-ForM_ items $ ¥item —> do
T. putStrLn $ mconcat 35 item 519/ element "link" &/ content
T. putStrLn $ mconcat $ item 515/ element "title" &/ content
T. putStrLn $ mconcat 55 item $/ element "description" &/ content
putStrLn ""
(&) = flip ($) (GHC—7.lO 73“5baselC§)K)
Be the first to comment