The xml-pipe package

[ Tags: bsd3, library, xml ] [ Propose Tags ]

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

Versions 0.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
Dependencies base (==4.*), bytestring (==0.10.*), papillon (==0.1.*), simple-pipe (>=0.0.0.14 && <0.2.0.0) [details]
License BSD3
Author Yoshikuni Jujo <PAF01143@nifty.ne.jp>
Maintainer Yoshikuni Jujo <PAF01143@nifty.ne.jp>
Category XML
Home page https://github.com/YoshikuniJujo/xml-pipe/wiki
Source repository head: 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)
Uploaded Mon Aug 25 02:00:23 UTC 2014 by YoshikuniJujo
Distributions NixOS:0.0.0.11
Downloads 2024 total (19 in the last 30 days)
Rating 0.0 (0 ratings) [clear rating]
  • λ
  • λ
  • λ
Status Docs available [build log]
Successful builds reported [all 1 reports]
Hackage Matrix CI

Modules

[Index]

Downloads

Maintainer's Corner

For package maintainers and hackage trustees