XML/XPath: Difference between revisions

m (Fixed lang tags.)
Line 268:
putStrLn "\n== Names ==\n"
print $ getsingleLineItems "name" xmlText</lang>
Using the Haskell XML Toolkit (HXT):
<lang haskell>{-# LANGUAGE Arrows #-}
import Text.XML.HXT.Arrow
 
deepElem name = deep (isElem >>> hasName name)
 
process = proc doc -> do
item <- single (deepElem "item") -< doc
_ <- listA (arrIO print <<< deepElem "price") -< doc
names <- listA (deepElem "name") -< doc
returnA -< (item, names)
main = do
[(item, names)] <- runX (readDocument [] "xmlpath.xml" >>> process)
print item
print names</lang>
 
=={{header|JavaScript}}==
Anonymous user