all tasks
This commit is contained in:
parent
b83f433714
commit
68f8f3e56b
14735 changed files with 178959 additions and 0 deletions
25
Task/XML-XPath/Haskell/xml-xpath-1.hs
Normal file
25
Task/XML-XPath/Haskell/xml-xpath-1.hs
Normal file
|
|
@ -0,0 +1,25 @@
|
|||
import Data.List
|
||||
import Control.Arrow
|
||||
import Control.Monad
|
||||
|
||||
takeWhileIncl :: (a -> Bool) -> [a] -> [a]
|
||||
takeWhileIncl _ [] = []
|
||||
takeWhileIncl p (x:xs)
|
||||
| p x = x : takeWhileIncl p xs
|
||||
| otherwise = [x]
|
||||
|
||||
getmultiLineItem n = takeWhileIncl(not.isInfixOf ("</" ++ n)). dropWhile(not.isInfixOf ('<': n))
|
||||
getsingleLineItems n = map (takeWhile(/='<'). drop 1. dropWhile(/='>')). filter (isInfixOf ('<': n))
|
||||
|
||||
main = do
|
||||
xml <- readFile "./Rosetta/xmlpath.xml"
|
||||
let xmlText = lines xml
|
||||
|
||||
putStrLn "\n== First item ==\n"
|
||||
mapM_ putStrLn $ head $ unfoldr (Just. liftM2 (id &&&) (\\) (getmultiLineItem "item")) xmlText
|
||||
|
||||
putStrLn "\n== Prices ==\n"
|
||||
mapM_ putStrLn $ getsingleLineItems "price" xmlText
|
||||
|
||||
putStrLn "\n== Names ==\n"
|
||||
print $ getsingleLineItems "name" xmlText
|
||||
Loading…
Add table
Add a link
Reference in a new issue