The xml-pipe package

[Tags: bsd3, library]

This package process subset of XML and is still far from perfect, now.

Example programs

examples/indians.hs

extensions

 import Control.Monad
 import "monads-tf" Control.Monad.Trans
 import Data.Maybe
 import Data.Pipe
 import Data.Pipe.List
 import Text.XML.Pipe

 import qualified Data.ByteString.Char8 as BSC

 littleIndians :: Int -> BSC.ByteString
 littleIndians n = "<indians>" `BSC.append`
 	BSC.pack (show n) `BSC.append` " little, " `BSC.append`
 	BSC.pack (show $ n + 1) `BSC.append` " little, " `BSC.append`
 	BSC.pack (show $ n + 2) `BSC.append` " little Indians" `BSC.append`
 	"</indians>"

 infiniteIndians :: [BSC.ByteString]
 infiniteIndians = map littleIndians [1, 4 .. ]

 xml :: [BSC.ByteString]
 xml = "<?xml version='1.0'?><song>" : infiniteIndians

 main :: IO ()
 main = void . runPipe $ fromList xml
 	=$= xmlEvent
 	=$= convert fromJust
 	=$= (xmlBegin >>= xmlNode)
 	=$= takeP 8
 	=$= printP

 takeP :: Monad m => Int -> Pipe a a m ()
 takeP 0 = return ()
 takeP n = do
 	mx <- await
 	maybe (return ()) (\x -> yield x >> takeP (n - 1)) mx

 convert :: Monad m => (a -> b) -> Pipe a b m ()
 convert f = do
 	mx <- await
 	maybe (return ()) (\x -> yield (f x) >> convert f) mx

 printP :: Show a => Pipe a () IO ()
 printP = do
 	mx <- await
 	maybe (return ()) (\x -> lift (print x) >> printP) mx

examples/starttls.hs

It process STARTTLS of XMPP as client. The fllowings are only main part.

 main :: IO ()
 main = do
 	h <- connectTo "localhost" (PortNumber 5222)
 	BS.hPut h $ xmlString begin
 	BS.hPut h $ xmlString startTls
 	void . runPipe $ handleP h
 		=$= xmlEvent
 		=$= convert fromJust
 		=$= (xmlBegin >>= xmlNodeUntil isProceed)
 		=$= printP
 	ca <- readCertificateStore ["cacert.sample_pem"]
 	g <- cprgCreate <$> createEntropyPool :: IO SystemRNG
 	(`run` g) $ do
 		p <- open' h "localhost" ["TLS_RSA_WITH_AES_128_CBC_SHA"] [] ca
 		hlPut p $ xmlString begin
 		void . runPipe $ handleP p
 			=$= xmlEvent
 			=$= convert fromJust
 			=$= (xmlBegin >>= xmlNode)
 			=$= printP

Properties

Versions0.0.0.0, 0.0.0.1, 0.0.0.2, 0.0.0.3, 0.0.0.4, 0.0.0.5, 0.0.0.6, 0.0.0.7, 0.0.0.8, 0.0.0.9, 0.0.0.10, 0.0.0.11
Dependenciesbase (==4.*), bytestring (==0.10.*), papillon (==0.1.*), simple-pipe (>=0.0.0.14 && <0.2.0.0)
LicenseBSD3
AuthorYoshikuni Jujo <PAF01143@nifty.ne.jp>
MaintainerYoshikuni Jujo <PAF01143@nifty.ne.jp>
StabilityExperimental
CategoryXML
Home pagehttps://github.com/YoshikuniJujo/xml-pipe/wiki
Source repositoryhead: git clone git://github.com/YoshikuniJujo/xml-pipe.git
this: git clone git://github.com/YoshikuniJujo/xml-pipe.git(tag xml-pipe-0.0.0.11)
UploadedMon Aug 25 02:00:23 UTC 2014 by YoshikuniJujo
DistributionsNixOS:0.0.0.11
Downloads939 total (110 in last 30 days)
StatusDocs available [build log]
Successful builds reported [all 1 reports]

Modules

[Index]

Downloads

Maintainers' corner

For package maintainers and hackage trustees