{-------------------------------------------------------------- - - The main program of the XQuery processor - Programmer: Leonidas Fegaras (fegaras@cse.uta.edu) - Date: 03/19/2008 - ---------------------------------------------------------------} {-# OPTIONS_GHC -fth #-} module Main where import XQuery f(d,s) = $(xe "{$s//firstname/text(),' ',$s//lastname/text()}") main = do a <- $(xq (" for $s in doc('data/cs.xml')//gradstudent " ++" order by $s/gpa descending, $s//lastname " ++" return {$s//firstname/text(),' ', " ++" $s//lastname/text(),' ', " ++" $s/gpa/text()} ")) putStrLn (show a) let query name = $(xq " doc('data/cs.xml')//gradstudent[.//lastname = $name]//firstname ") b <- query $(xe " 'Galanis' ") -- or use: query [XText "Galanis"] putStrLn (show b) c <- $(xq (" { " ++" let $d := doc('data/cs.xml') " ++" for $s in $d//gradstudent " ++" where $s/gpa = '4.0' " ++" return f($d//deptname,$s) " ++" } ")) putStrLn (show c) let q file = $(xq (" let $d := doc($file)//gradstudent " ++" return ($d/../deptname,count($d)) ")) d <- q $(xe "'data/cs.xml'") putStrLn (show d) putStrLn "Type an XQuery:" iquery <- getLine e <- xquery iquery -- Use the XQuery interpreter putStrLn (show e)