packages feed

hexpat 0.7 → 0.8

raw patch · 4 files changed

+26/−9 lines, 4 filesPVP ok

version bump matches the API change (PVP)

API changes (from Hackage documentation)

+ Text.XML.Expat.Tree: extractText :: (Monoid text) => Node tag text -> text
- Text.XML.Expat.Tree: parseSAX :: (Show tag, Show text, GenericXMLString tag, GenericXMLString text) => Maybe Encoding -> ByteString -> [SAXEvent tag text]
+ Text.XML.Expat.Tree: parseSAX :: (GenericXMLString tag, GenericXMLString text) => Maybe Encoding -> ByteString -> [SAXEvent tag text]
- Text.XML.Expat.Tree: parseSAXThrowing :: (Show tag, Show text, GenericXMLString tag, GenericXMLString text) => Maybe Encoding -> ByteString -> [SAXEvent tag text]
+ Text.XML.Expat.Tree: parseSAXThrowing :: (GenericXMLString tag, GenericXMLString text) => Maybe Encoding -> ByteString -> [SAXEvent tag text]
- Text.XML.Expat.Tree: parseTree :: (Show tag, Show text, GenericXMLString tag, GenericXMLString text) => Maybe Encoding -> ByteString -> (Node tag text, Maybe XMLParseError)
+ Text.XML.Expat.Tree: parseTree :: (GenericXMLString tag, GenericXMLString text) => Maybe Encoding -> ByteString -> (Node tag text, Maybe XMLParseError)
- Text.XML.Expat.Tree: parseTreeThrowing :: (Show tag, Show text, GenericXMLString tag, GenericXMLString text) => Maybe Encoding -> ByteString -> Node tag text
+ Text.XML.Expat.Tree: parseTreeThrowing :: (GenericXMLString tag, GenericXMLString text) => Maybe Encoding -> ByteString -> Node tag text

Files

Text/XML/Expat/Format.hs view
@@ -2,7 +2,7 @@ -- Copyright (C) 2008 Evan Martin <martine@danga.com> -- Copyright (C) 2009 Stephen Blackheath <http://blacksapphire.com/antispam> --- | This module provides lazy functions to format a tree+-- | This module provides functions to format a tree -- structure as UTF-8 encoded XML.  {-# LANGUAGE FlexibleContexts #-}@@ -73,7 +73,7 @@         putByteString $ gxToByteString aname         putByteString $ pack "=\""         putXMLText $ gxToByteString avalue-        putByteString $ pack "\"" +        putByteString $ pack "\""     if null children         then             putByteString $ pack "/>"@@ -83,6 +83,7 @@             putByteString $ pack "</"             putThisTag             putWord8 $ c2w '>'+    flush putNode (Text txt) =     putXMLText $ gxToByteString txt 
Text/XML/Expat/Tree.hs view
@@ -91,6 +91,7 @@   UNode,   UNodes,   UAttributes,+  extractText,   -- * Parse to tree   parseTree,   parseTree',@@ -122,6 +123,7 @@ import qualified Data.Text.Encoding as TE import qualified Codec.Binary.UTF8.String as U8 import Data.Binary.Put+import Data.Monoid import Data.Typeable import Control.Exception.Extensible as Exc import Control.Applicative@@ -222,6 +224,12 @@ -- text are the same string type. type UAttributes text = Attributes text text +-- | Extract all text content from inside a tag into a single string, including+-- any text contained in children.+extractText :: Monoid text => Node tag text -> text+extractText (Element _ _ children) = mconcat $ map extractText children+extractText (Text txt) = txt+ modifyChildren :: ([Node tag text] -> [Node tag text])                -> Node tag text                -> Node tag text@@ -288,7 +296,7 @@  -- | Lazily parse XML to SAX events. In the event of an error, FailDocument is -- the last element of the output list.-parseSAX :: (Show tag, Show text, GenericXMLString tag, GenericXMLString text) =>+parseSAX :: (GenericXMLString tag, GenericXMLString text) =>             Maybe Encoding      -- ^ Optional encoding override          -> L.ByteString        -- ^ Input text (a lazy ByteString)          -> [SAXEvent tag text]@@ -337,7 +345,7 @@ instance Exception XMLParseException where  -- | Lazily parse XML to SAX events. In the event of an error, throw 'XMLParseException'.-parseSAXThrowing :: (Show tag, Show text, GenericXMLString tag, GenericXMLString text) =>+parseSAXThrowing :: (GenericXMLString tag, GenericXMLString text) =>                     Maybe Encoding      -- ^ Optional encoding override                  -> L.ByteString        -- ^ Input text (a lazy ByteString)                  -> [SAXEvent tag text]@@ -414,16 +422,15 @@ -- | Lazily parse XML to tree. Note that forcing the XMLParseError return value -- will force the entire parse.  Therefore, to ensure lazy operation, don't -- check the error status until you have processed the tree.-parseTree :: (Show tag, Show text, GenericXMLString tag, GenericXMLString text) =>+parseTree :: (GenericXMLString tag, GenericXMLString text) =>              Maybe Encoding      -- ^ Optional encoding override           -> L.ByteString        -- ^ Input text (a lazy ByteString)           -> (Node tag text, Maybe XMLParseError) parseTree mEnc bs = saxToTree $ parseSAX mEnc bs  -- | Lazily parse XML to tree. In the event of an error, throw 'XMLParseException'.-parseTreeThrowing :: (Show tag, Show text, GenericXMLString tag, GenericXMLString text) =>+parseTreeThrowing :: (GenericXMLString tag, GenericXMLString text) =>              Maybe Encoding      -- ^ Optional encoding override           -> L.ByteString        -- ^ Input text (a lazy ByteString)           -> Node tag text parseTreeThrowing mEnc bs = fst $ saxToTree $ parseSAXThrowing mEnc bs-
hexpat.cabal view
@@ -1,6 +1,6 @@ Cabal-Version: >= 1.2 Name: hexpat-Version: 0.7+Version: 0.8 Synopsis: wrapper for expat, the fast XML parser Description:   Expat (<http://expat.sourceforge.net/>) is a stream-oriented XML parser
test/tests.hs view
@@ -116,6 +116,14 @@         ["start open","start test1","end test1","start hello","end hello","end open"]         l +test_extractText = do+    let tree = Element "cheese" [("type", "edam")]+            [Text "You don't actually ",+             Element "sub" [] [Text "have any "],+             Text "cheese at all",+             Text ", do you?"]+    assertEqual "extractText" "You don't actually have any cheese at all, do you?" (extractText tree)+ main = do     testXML <- readFile "test.xml"     -- Remove trailing newline@@ -150,6 +158,7 @@         TestCase $ test_error2,         TestCase $ test_error3,         TestCase $ test_error4,-        TestCase $ test_parse+        TestCase $ test_parse,+        TestCase $ test_extractText       ]