-- Hoogle documentation, generated by Haddock -- See Hoogle, http://www.haskell.org/hoogle/ -- | wrapper for expat, the fast XML parser -- -- This package provides a general purpose Haskell XML library using -- Expat to do its parsing (http://expat.sourceforge.net/ - a fast -- stream-oriented XML parser written in C). It is extensible to any -- string type, with String, ByteString and -- Text provided out of the box. -- -- Basic usage: Parsing a tree (Tree), formatting a tree -- (Format). -- -- Other features: Helpers for processing XML trees (Proc), trees -- annotated with XML source location (Annotated), XML cursors -- (Cursor), more intelligent handling of qualified tag names -- (Qualified), tags qualified with namespaces -- (Namespaced), SAX-style parse (SAX), and access to the -- low-level interface in case speed is paramount (IO). -- -- The design goals are speed, speed, speed, interface simplicity and -- modular design. -- -- For examples, see Text.XML.Expat.Tree module. For benchmarks, -- http://haskell.org/haskellwiki/Hexpat/ -- -- Credits to Iavor Diatchki and the xml (XML.Light) package for -- Proc and Cursor. -- -- INSTALLATION: Unix install requires an OS package called something -- like libexpat-dev. On MacOSX, expat comes with Apple's -- optional X11 package, or you can install it from source. To install on -- Windows, first install the Windows binary that's available from -- http://expat.sourceforge.net/, then type (assuming you're using -- v2.0.1): -- --
--   cabal install hexpat --extra-lib-dirs=C:\Program Files\Expat 2.0.1\Bin --extra-include-dirs=C:\Program Files\Expat 2.0.1\Source\Lib
--   
-- -- Ensure libexpat.dll can be found in your system PATH (or copy -- it into your executable's directory). @package hexpat @version 0.13 -- | Low-level interface to Expat. Unless speed is paramount, this should -- normally be avoided in favour of the interfaces provided by -- Text.XML.Expat.SAX and Text.XML.Expat.Tree. Basic usage is: -- --
    --
  1. Make a new parser: newParser.
  2. --
  3. Set up callbacks on the parser: setStartElementHandler, -- etc.
  4. --
  5. Feed data into the parser: parse, parse' or -- parseChunk.
  6. --
module Text.XML.Expat.IO data Parser -- | Create a Parser. newParser :: Maybe Encoding -> IO Parser -- | parse data feeds lazy ByteString data into a -- Parser. It returns Nothing on success, or Just the parse error. parse :: Parser -> ByteString -> IO (Maybe XMLParseError) -- | parse data feeds strict ByteString data into a -- Parser. It returns Nothing on success, or Just the parse error. parse' :: Parser -> ByteString -> IO (Maybe XMLParseError) -- | parseChunk data False feeds strict ByteString data -- into a Parser. The end of the data is indicated by passing -- True for the final parameter. It returns Nothing on success, -- or Just the parse error. parseChunk :: Parser -> ByteString -> Bool -> IO (Maybe XMLParseError) -- | Encoding types available for the document encoding. data Encoding ASCII :: Encoding UTF8 :: Encoding UTF16 :: Encoding ISO88591 :: Encoding -- | Parse error, consisting of message text and error location data XMLParseError XMLParseError :: String -> XMLParseLocation -> XMLParseError getParseLocation :: Parser -> IO XMLParseLocation -- | Specifies a location of an event within the input text data XMLParseLocation XMLParseLocation :: Int64 -> Int64 -> Int64 -> Int64 -> XMLParseLocation -- | Line number of the event xmlLineNumber :: XMLParseLocation -> Int64 -- | Column number of the event xmlColumnNumber :: XMLParseLocation -> Int64 -- | Byte index of event from start of document xmlByteIndex :: XMLParseLocation -> Int64 -- | The number of bytes in the event xmlByteCount :: XMLParseLocation -> Int64 -- | The type of the "element started" callback. The first parameter is the -- element name; the second are the (attribute, value) pairs. Return True -- to continue parsing as normal, or False to terminate the parse. type StartElementHandler = CString -> [(CString, CString)] -> IO Bool -- | The type of the "element ended" callback. The parameter is the element -- name. Return True to continue parsing as normal, or False to terminate -- the parse. type EndElementHandler = CString -> IO Bool -- | The type of the "character data" callback. The parameter is the -- character data processed. This callback may be called more than once -- while processing a single conceptual block of text. Return True to -- continue parsing as normal, or False to terminate the parse. type CharacterDataHandler = CStringLen -> IO Bool -- | The type of the "external entity reference" callback. See the expat -- documentation. type ExternalEntityRefHandler = Parser -> CString -> CString -> CString -> CString -> IO Bool -- | Set a skipped entity handler. This is called in two situations: -- -- 1. An entity reference is encountered for which no declaration has -- been read and this is not an error. -- -- 2. An internal entity reference is read, but not expanded, because -- XML_SetDefaultHandler has been called. type SkippedEntityHandler = CString -> Int -> IO Bool -- | Attach a StartElementHandler to a Parser. setStartElementHandler :: Parser -> StartElementHandler -> IO () -- | Attach an EndElementHandler to a Parser. setEndElementHandler :: Parser -> EndElementHandler -> IO () -- | Attach an CharacterDataHandler to a Parser. setCharacterDataHandler :: Parser -> CharacterDataHandler -> IO () setExternalEntityRefHandler :: Parser -> ExternalEntityRefHandler -> IO () setSkippedEntityHandler :: Parser -> SkippedEntityHandler -> IO () setUseForeignDTD :: Parser -> Bool -> IO () parseExternalEntityReference :: Parser -> CString -> Maybe Encoding -> CStringLen -> IO Bool -- | This variant of parseChunk must either be called inside -- withHandlers (safest), or between unsafeSetHandlers and -- unsafeReleaseHandlers, and this will give you better -- performance than parseChunk if you process multiple chunks -- inside. unsafeParseChunk :: Parser -> ByteString -> Bool -> IO (Maybe XMLParseError) -- | unsafeParseChunk is required to be called inside -- withHandlers. Safer than using unsafeSetHandlers / -- unsafeReleaseHandlers. withHandlers :: Parser -> IO a -> IO a unsafeSetHandlers :: Parser -> IO ExpatHandlers unsafeReleaseHandlers :: ExpatHandlers -> IO () data ExpatHandlers encodingToString :: Encoding -> String instance Eq XMLParseLocation instance Show XMLParseLocation instance Eq XMLParseError instance Show XMLParseError instance NFData XMLParseLocation instance NFData XMLParseError instance Show Parser -- | This module provides functions to parse an XML document to a lazy -- stream of SAX events. module Text.XML.Expat.SAX -- | Encoding types available for the document encoding. data Encoding ASCII :: Encoding UTF8 :: Encoding UTF16 :: Encoding ISO88591 :: Encoding -- | Parse error, consisting of message text and error location data XMLParseError XMLParseError :: String -> XMLParseLocation -> XMLParseError -- | Specifies a location of an event within the input text data XMLParseLocation XMLParseLocation :: Int64 -> Int64 -> Int64 -> Int64 -> XMLParseLocation -- | Line number of the event xmlLineNumber :: XMLParseLocation -> Int64 -- | Column number of the event xmlColumnNumber :: XMLParseLocation -> Int64 -- | Byte index of event from start of document xmlByteIndex :: XMLParseLocation -> Int64 -- | The number of bytes in the event xmlByteCount :: XMLParseLocation -> Int64 data ParserOptions tag text ParserOptions :: Maybe Encoding -> Maybe (tag -> Maybe text) -> ParserOptions tag text -- | The encoding parameter, if provided, overrides the document's encoding -- declaration. parserEncoding :: ParserOptions tag text -> Maybe Encoding -- | If provided, entity references (i.e.   and friends) -- will be decoded into text using the supplied lookup function entityDecoder :: ParserOptions tag text -> Maybe (tag -> Maybe text) data SAXEvent tag text StartElement :: tag -> [(tag, text)] -> SAXEvent tag text EndElement :: tag -> SAXEvent tag text CharacterData :: text -> SAXEvent tag text FailDocument :: XMLParseError -> SAXEvent tag text -- | Converts a CString to a GenericXMLString type. mkText :: (GenericXMLString text) => CString -> IO text -- | Lazily parse XML to SAX events. In the event of an error, FailDocument -- is the last element of the output list. parse :: (GenericXMLString tag, GenericXMLString text) => ParserOptions tag text -> ByteString -> [SAXEvent tag text] -- | A variant of parseSAX that gives a document location with each SAX -- event. parseLocations :: (GenericXMLString tag, GenericXMLString text) => ParserOptions tag text -> ByteString -> [(SAXEvent tag text, XMLParseLocation)] -- | A variant of parseSAX that gives a document location with each SAX -- event. In the event of an error, throw XMLParseException. -- -- parseLocationsThrowing can throw an exception from pure code, -- which is generally a bad way to handle errors, because Haskell's lazy -- evaluation means it's hard to predict where it will be thrown from. -- However, it may be acceptable in situations where it's not expected -- during normal operation, depending on the design of your program. parseLocationsThrowing :: (GenericXMLString tag, GenericXMLString text) => ParserOptions tag text -> ByteString -> [(SAXEvent tag text, XMLParseLocation)] -- | Lazily parse XML to SAX events. In the event of an error, throw -- XMLParseException. -- -- parseThrowing can throw an exception from pure code, which is -- generally a bad way to handle errors, because Haskell's lazy -- evaluation means it's hard to predict where it will be thrown from. -- However, it may be acceptable in situations where it's not expected -- during normal operation, depending on the design of your program. parseThrowing :: (GenericXMLString tag, GenericXMLString text) => ParserOptions tag text -> ByteString -> [SAXEvent tag text] defaultParserOptions :: ParserOptions tag text -- | An exception indicating an XML parse error, used by the -- ..Throwing variants. data XMLParseException XMLParseException :: XMLParseError -> XMLParseException -- | DEPRECATED: Use parse instead. -- -- Lazily parse XML to SAX events. In the event of an error, FailDocument -- is the last element of the output list. Deprecated in favour of new -- parse parseSAX :: (GenericXMLString tag, GenericXMLString text) => Maybe Encoding -> ByteString -> [SAXEvent tag text] -- | DEPRECATED: Use parseLocations instead. -- -- A variant of parseSAX that gives a document location with each SAX -- event. parseSAXLocations :: (GenericXMLString tag, GenericXMLString text) => Maybe Encoding -> ByteString -> [(SAXEvent tag text, XMLParseLocation)] -- | DEPRECATED: Used parseLocationsThrowing instead. -- -- A variant of parseSAX that gives a document location with each SAX -- event. In the event of an error, throw XMLParseException. parseSAXLocationsThrowing :: (GenericXMLString tag, GenericXMLString text) => Maybe Encoding -> ByteString -> [(SAXEvent tag text, XMLParseLocation)] -- | DEPRECATED: Use parseThrowing instead. -- -- Lazily parse XML to SAX events. In the event of an error, throw -- XMLParseException. parseSAXThrowing :: (GenericXMLString tag, GenericXMLString text) => Maybe Encoding -> ByteString -> [SAXEvent tag text] -- | An abstraction for any string type you want to use as xml text (that -- is, attribute values or element text content). If you want to use a -- new string type with hexpat, you must make it an instance of -- GenericXMLString. class (Monoid s, Eq s) => GenericXMLString s gxNullString :: (GenericXMLString s) => s -> Bool gxToString :: (GenericXMLString s) => s -> String gxFromString :: (GenericXMLString s) => String -> s gxFromChar :: (GenericXMLString s) => Char -> s gxHead :: (GenericXMLString s) => s -> Char gxTail :: (GenericXMLString s) => s -> s gxBreakOn :: (GenericXMLString s) => Char -> s -> (s, s) gxFromCStringLen :: (GenericXMLString s) => CStringLen -> IO s gxToByteString :: (GenericXMLString s) => s -> ByteString instance Typeable XMLParseException instance Eq XMLParseException instance Show XMLParseException instance (Eq tag, Eq text) => Eq (SAXEvent tag text) instance (Show tag, Show text) => Show (SAXEvent tag text) instance Exception XMLParseException instance (NFData tag, NFData text) => NFData (SAXEvent tag text) instance GenericXMLString Text instance GenericXMLString ByteString instance GenericXMLString String -- | A typeclass to allow for functions that work with different node types -- such as the ones defined in Tree and Annotated. module Text.XML.Expat.NodeClass -- | Extract all text content from inside a tag into a single string, -- including any text contained in children. textContent :: (NodeClass n [], Monoid text) => n [] tag text -> text class (List c) => NodeClass n c isElement :: (NodeClass n c) => n c tag text -> Bool isText :: (NodeClass n c) => n c tag text -> Bool textContentM :: (NodeClass n c, Monoid text) => n c tag text -> ItemM c text isNamed :: (NodeClass n c, Eq tag) => tag -> n c tag text -> Bool getName :: (NodeClass n c, Monoid tag) => n c tag text -> tag getAttributes :: (NodeClass n c) => n c tag text -> [(tag, text)] getChildren :: (NodeClass n c) => n c tag text -> c (n c tag text) getText :: (NodeClass n c, Monoid text) => n c tag text -> text modifyName :: (NodeClass n c) => (tag -> tag) -> n c tag text -> n c tag text modifyAttributes :: (NodeClass n c) => ([(tag, text)] -> [(tag, text)]) -> n c tag text -> n c tag text modifyChildren :: (NodeClass n c) => (c (n c tag text) -> c (n c tag text)) -> n c tag text -> n c tag text mapAllTags :: (NodeClass n c) => (tag -> tag') -> n c tag text -> n c tag' text mapElement :: (NodeClass n c) => ((tag, [(tag, text)], c (n c tag text)) -> (tag', [(tag', text)], c (n c tag' text))) -> n c tag text -> n c tag' text mapNodeContainer :: (NodeClass n c) => (c (n c tag text) -> ItemM c (c' (n c' tag text))) -> n c tag text -> ItemM c (n c' tag text) -- | Get the value of the attribute having the specified name. getAttribute :: (NodeClass n c, GenericXMLString tag) => n c tag text -> tag -> Maybe text -- | Set the value of the attribute with the specified name to the value, -- overwriting the first existing attribute with that name if present. setAttribute :: (Eq tag, NodeClass n c, GenericXMLString tag) => tag -> text -> n c tag text -> n c tag text -- | Delete the first attribute matching the specified name. deleteAttribute :: (Eq tag, NodeClass n c, GenericXMLString tag) => tag -> n c tag text -> n c tag text -- | setAttribute if Just, deleteAttribute if Nothing. alterAttribute :: (Eq tag, NodeClass n c, GenericXMLString tag) => tag -> Maybe text -> n c tag text -> n c tag text -- | This module provides functions to parse an XML document to a tree -- structure, either strictly or lazily. -- -- The GenericXMLString type class allows you to use any string -- type. Three string types are provided for here: String, -- ByteString and Text. -- -- Here is a complete example to get you started: -- --
--   -- | A "hello world" example of hexpat that lazily parses a document, printing
--   -- it to standard out.
--   
--   import Text.XML.Expat.Tree
--   import Text.XML.Expat.Format
--   import System.Environment
--   import System.Exit
--   import System.IO
--   import qualified Data.ByteString.Lazy as L
--   
--   main = do
--       args <- getArgs
--       case args of
--           [filename] -> process filename
--           otherwise  -> do
--               hPutStrLn stderr "Usage: helloworld <file.xml>"
--               exitWith $ ExitFailure 1
--   
--   process :: String -> IO ()
--   process filename = do
--       inputText <- L.readFile filename
--       -- Note: Because we're not using the tree, Haskell can't infer the type of
--       -- strings we're using so we need to tell it explicitly with a type signature.
--       let (xml, mErr) = parse defaultParserOptions inputText :: (UNode String, Maybe XMLParseError)
--       -- Process document before handling error, so we get lazy processing.
--       L.hPutStr stdout $ format xml
--       putStrLn ""
--       case mErr of
--           Nothing -> return ()
--           Just err -> do
--               hPutStrLn stderr $ "XML parse failed: "++show err
--               exitWith $ ExitFailure 2
--   
-- -- Error handling in strict parses is very straight forward - just check -- the Either return value. Lazy parses are not so simple. Here -- are two working examples that illustrate the ways to handle errors. -- Here they are: -- -- Way no. 1 - Using a Maybe value -- --
--   import Text.XML.Expat.Tree
--   import qualified Data.ByteString.Lazy as L
--   import Data.ByteString.Internal (c2w)
--   
--   -- This is the recommended way to handle errors in lazy parses
--   main = do
--       let (tree, mError) = parse defaultParserOptions
--                      (L.pack $ map c2w $ "<top><banana></apple></top>")
--       print (tree :: UNode String)
--   
--       -- Note: We check the error _after_ we have finished our processing
--       -- on the tree.
--       case mError of
--           Just err -> putStrLn $ "It failed : "++show err
--           Nothing -> putStrLn "Success!"
--   
-- -- Way no. 2 - Using exceptions -- -- parseThrowing can throw an exception from pure code, which is -- generally a bad way to handle errors, because Haskell's lazy -- evaluation means it's hard to predict where it will be thrown from. -- However, it may be acceptable in situations where it's not expected -- during normal operation, depending on the design of your program. -- --
--   ...
--   import Control.Exception.Extensible as E
--   
--   -- This is not the recommended way to handle errors.
--   main = do
--       do
--           let tree = parseThrowing defaultParserOptions
--                          (L.pack $ map c2w $ "<top><banana></apple></top>")
--           print (tree :: UNode String)
--           -- Because of lazy evaluation, you should not process the tree outside
--           -- the 'do' block, or exceptions could be thrown that won't get caught.
--       `E.catch` (\exc ->
--           case E.fromException exc of
--               Just (XMLParseException err) -> putStrLn $ "It failed : "++show err
--               Nothing -> E.throwIO exc)
--   
module Text.XML.Expat.Tree -- | The tree representation of the XML document. data NodeG c tag text Element :: !tag -> ![(tag, text)] -> c (NodeG c tag text) -> NodeG c tag text eName :: NodeG c tag text -> !tag eAttributes :: NodeG c tag text -> ![(tag, text)] eChildren :: NodeG c tag text -> c (NodeG c tag text) Text :: !text -> NodeG c tag text -- | A pure Node that uses a list as its container type. type Node = NodeG [] -- | Type shortcut for attributes type Attributes tag text = [(tag, text)] -- | Type shortcut for a single node with unqualified tag names where tag -- and text are the same string type. type UNode text = Node text text -- | Type shortcut for attributes with unqualified names where tag and 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. textContent :: (NodeClass n [], Monoid text) => n [] tag text -> text -- | Is the given node an element? isElement :: (NodeClass n c) => n c tag text -> Bool -- | Is the given node a tag with the given name? isNamed :: (NodeClass n c, Eq tag) => tag -> n c tag text -> Bool -- | Is the given node text? isText :: (NodeClass n c) => n c tag text -> Bool -- | Get the name of this node if it's an element, return empty string -- otherwise. getName :: (NodeClass n c, Monoid tag) => n c tag text -> tag -- | Get the attributes of a node if it's an element, return empty list -- otherwise. getAttributes :: (NodeClass n c) => n c tag text -> [(tag, text)] -- | Get the value of the attribute having the specified name. getAttribute :: (NodeClass n c, GenericXMLString tag) => n c tag text -> tag -> Maybe text -- | Get children of a node if it's an element, return empty list -- otherwise. getChildren :: (NodeClass n c) => n c tag text -> c (n c tag text) -- | Modify name if it's an element, no-op otherwise. modifyName :: (NodeClass n c) => (tag -> tag) -> n c tag text -> n c tag text -- | Modify attributes if it's an element, no-op otherwise. modifyAttributes :: (NodeClass n c) => ([(tag, text)] -> [(tag, text)]) -> n c tag text -> n c tag text -- | Set the value of the attribute with the specified name to the value, -- overwriting the first existing attribute with that name if present. setAttribute :: (Eq tag, NodeClass n c, GenericXMLString tag) => tag -> text -> n c tag text -> n c tag text -- | Delete the first attribute matching the specified name. deleteAttribute :: (Eq tag, NodeClass n c, GenericXMLString tag) => tag -> n c tag text -> n c tag text -- | setAttribute if Just, deleteAttribute if Nothing. alterAttribute :: (Eq tag, NodeClass n c, GenericXMLString tag) => tag -> Maybe text -> n c tag text -> n c tag text -- | Modify children (non-recursively) if it's an element, no-op otherwise. modifyChildren :: (NodeClass n c) => (c (n c tag text) -> c (n c tag text)) -> n c tag text -> n c tag text -- | Map all tags (both tag names and attribute names) recursively. mapAllTags :: (NodeClass n c) => (tag -> tag') -> n c tag text -> n c tag' text data ParserOptions tag text ParserOptions :: Maybe Encoding -> Maybe (tag -> Maybe text) -> ParserOptions tag text -- | The encoding parameter, if provided, overrides the document's encoding -- declaration. parserEncoding :: ParserOptions tag text -> Maybe Encoding -- | If provided, entity references (i.e. &nbsp; and friends) -- will be decoded into text using the supplied lookup function entityDecoder :: ParserOptions tag text -> Maybe (tag -> Maybe text) defaultParserOptions :: ParserOptions tag text -- | Encoding types available for the document encoding. data Encoding ASCII :: Encoding UTF8 :: Encoding UTF16 :: Encoding ISO88591 :: Encoding -- | 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. parse :: (GenericXMLString tag, GenericXMLString text) => ParserOptions tag text -> ByteString -> (Node tag text, Maybe XMLParseError) -- | Strictly parse XML to tree. Returns error message or valid parsed -- tree. parse' :: (GenericXMLString tag, GenericXMLString text) => ParserOptions tag text -> ByteString -> Either XMLParseError (Node tag text) -- | Parse error, consisting of message text and error location data XMLParseError XMLParseError :: String -> XMLParseLocation -> XMLParseError -- | Specifies a location of an event within the input text data XMLParseLocation XMLParseLocation :: Int64 -> Int64 -> Int64 -> Int64 -> XMLParseLocation -- | Line number of the event xmlLineNumber :: XMLParseLocation -> Int64 -- | Column number of the event xmlColumnNumber :: XMLParseLocation -> Int64 -- | Byte index of event from start of document xmlByteIndex :: XMLParseLocation -> Int64 -- | The number of bytes in the event xmlByteCount :: XMLParseLocation -> Int64 -- | Lazily parse XML to tree. In the event of an error, throw -- XMLParseException. -- -- parseThrowing can throw an exception from pure code, which is -- generally a bad way to handle errors, because Haskell's lazy -- evaluation means it's hard to predict where it will be thrown from. -- However, it may be acceptable in situations where it's not expected -- during normal operation, depending on the design of your program. parseThrowing :: (GenericXMLString tag, GenericXMLString text) => ParserOptions tag text -> ByteString -> Node tag text -- | An exception indicating an XML parse error, used by the -- ..Throwing variants. data XMLParseException XMLParseException :: XMLParseError -> XMLParseException data SAXEvent tag text StartElement :: tag -> [(tag, text)] -> SAXEvent tag text EndElement :: tag -> SAXEvent tag text CharacterData :: text -> SAXEvent tag text FailDocument :: XMLParseError -> SAXEvent tag text -- | A lower level function that lazily converts a SAX stream into a tree -- structure. saxToTree :: (GenericXMLString tag) => [SAXEvent tag text] -> (Node tag text, Maybe XMLParseError) -- | An abstraction for any string type you want to use as xml text (that -- is, attribute values or element text content). If you want to use a -- new string type with hexpat, you must make it an instance of -- GenericXMLString. class (Monoid s, Eq s) => GenericXMLString s gxNullString :: (GenericXMLString s) => s -> Bool gxToString :: (GenericXMLString s) => s -> String gxFromString :: (GenericXMLString s) => String -> s gxFromChar :: (GenericXMLString s) => Char -> s gxHead :: (GenericXMLString s) => s -> Char gxTail :: (GenericXMLString s) => s -> s gxBreakOn :: (GenericXMLString s) => Char -> s -> (s, s) gxFromCStringLen :: (GenericXMLString s) => CStringLen -> IO s gxToByteString :: (GenericXMLString s) => s -> ByteString eAttrs :: Node tag text -> [(tag, text)] -- | DEPRECATED: Use [Node tag text] instead. -- -- Type shortcut for nodes. type Nodes tag text = [Node tag text] -- | DEPRECATED: Use [UNode text] instead. -- -- Type shortcut for nodes with unqualified tag names where tag and text -- are the same string type. Deprecated type UNodes text = Nodes text text -- | DEPREACTED: Use parse instead. -- -- 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 :: (GenericXMLString tag, GenericXMLString text) => Maybe Encoding -> ByteString -> (Node tag text, Maybe XMLParseError) -- | DEPRECATED: use parse instead. -- -- Strictly parse XML to tree. Returns error message or valid parsed -- tree. parseTree' :: (GenericXMLString tag, GenericXMLString text) => Maybe Encoding -> ByteString -> Either XMLParseError (Node tag text) -- | DEPRECATED: Use parse instead. -- -- Lazily parse XML to SAX events. In the event of an error, FailDocument -- is the last element of the output list. Deprecated in favour of new -- parse parseSAX :: (GenericXMLString tag, GenericXMLString text) => Maybe Encoding -> ByteString -> [SAXEvent tag text] -- | DEPRECATED: Use parseLocations instead. -- -- A variant of parseSAX that gives a document location with each SAX -- event. parseSAXLocations :: (GenericXMLString tag, GenericXMLString text) => Maybe Encoding -> ByteString -> [(SAXEvent tag text, XMLParseLocation)] -- | DEPRECATED: Use parseThrowing instead. -- -- Lazily parse XML to tree. In the event of an error, throw -- XMLParseException. parseTreeThrowing :: (GenericXMLString tag, GenericXMLString text) => Maybe Encoding -> ByteString -> Node tag text -- | DEPRECATED: Use parseThrowing instead. -- -- Lazily parse XML to SAX events. In the event of an error, throw -- XMLParseException. parseSAXThrowing :: (GenericXMLString tag, GenericXMLString text) => Maybe Encoding -> ByteString -> [SAXEvent tag text] -- | DEPRECATED: Used parseLocationsThrowing instead. -- -- A variant of parseSAX that gives a document location with each SAX -- event. In the event of an error, throw XMLParseException. parseSAXLocationsThrowing :: (GenericXMLString tag, GenericXMLString text) => Maybe Encoding -> ByteString -> [(SAXEvent tag text, XMLParseLocation)] instance (Functor c, List c) => NodeClass NodeG c instance (NFData tag, NFData text) => NFData (NodeG [] tag text) instance (Eq tag, Eq text) => Eq (NodeG [] tag text) instance (Show tag, Show text) => Show (NodeG [] tag text) -- | In the default representation, qualified tag and attribute names such -- as <abc:hello> are represented just as a string containing a -- colon, e.g. "abc:hello". -- -- This module provides functionality to handle these more intelligently, -- splitting all tag and attribute names into their Prefix and LocalPart -- components. module Text.XML.Expat.Qualified -- | A qualified name. -- -- Qualified names have two parts, a prefix and a local part. The local -- part is the name of the tag. The prefix scopes that name to a -- particular group of legal tags. -- -- The prefix will usually be associated with a namespace URI. This is -- usually achieved by using xmlns attributes to bind prefixes to URIs. data QName text QName :: Maybe text -> !text -> QName text qnPrefix :: QName text -> Maybe text qnLocalPart :: QName text -> !text -- | Type shortcut for a single node where qualified names are used for -- tags type QNode text = Node (QName text) text -- | DEPRECATED: Use [QNode text] instead. -- -- Type shortcut for nodes where qualified names are used for tags type QNodes text = [Node (QName text) text] -- | Type shortcut for attributes with qualified names type QAttributes text = Attributes (QName text) text -- | Make a new QName from a prefix and localPart. mkQName :: text -> text -> QName text -- | Make a new QName with no prefix. mkAnQName :: text -> QName text toQualified :: (NodeClass n c, GenericXMLString text) => n c text text -> n c (QName text) text fromQualified :: (NodeClass n c, GenericXMLString text) => n c (QName text) text -> n c text text instance (Eq text) => Eq (QName text) instance (Show text) => Show (QName text) instance (NFData text) => NFData (QName text) module Text.XML.Expat.Namespaced -- | A namespace-qualified tag. -- -- NName has two components, a local part and an optional namespace. The -- local part is the name of the tag. The namespace is the URI -- identifying collections of declared tags. Tags with the same local -- part but from different namespaces are distinct. Unqualified tags are -- those with no namespace. They are in the default namespace, and all -- uses of an unqualified tag are equivalent. data NName text NName :: Maybe text -> !text -> NName text nnNamespace :: NName text -> Maybe text nnLocalPart :: NName text -> !text -- | Type shortcut for a single node where namespaced names are used for -- tags type NNode text = Node (NName text) text -- | DEPRECATED: Use [NNode text] instead. -- -- Type shortcut for nodes where namespaced names are used for tags. type NNodes text = [Node (NName text) text] -- | Type shortcut for attributes with namespaced names type NAttributes text = Attributes (NName text) text -- | Make a new NName from a prefix and localPart. mkNName :: text -> text -> NName text -- | Make a new NName with no prefix. mkAnNName :: text -> NName text toNamespaced :: (NodeClass n c, GenericXMLString text, Ord text, Show text, Functor c) => n c (QName text) text -> n c (NName text) text fromNamespaced :: (NodeClass n c, GenericXMLString text, Ord text, Functor c) => n c (NName text) text -> n c (QName text) text xmlnsUri :: (GenericXMLString text) => text xmlns :: (GenericXMLString text) => text instance (Eq text) => Eq (NName text) instance (Show text) => Show (NName text) instance (NFData text) => NFData (NName text) -- | This module ported from Text.XML.Light.Cursor -- -- XML cursors for working XML content withing the context of an XML -- document. This implementation is based on the general tree zipper -- written by Krasimir Angelov and Iavor S. Diatchki. module Text.XML.Expat.Cursor data Tag tag text Tag :: tag -> Attributes tag text -> Tag tag text tagName :: Tag tag text -> tag tagAttribs :: Tag tag text -> Attributes tag text getTag :: Node tag text -> Tag tag text fromTag :: Tag tag text -> [Node tag text] -> Node tag text -- | The position of a piece of content in an XML document. data Cursor tag text Cur :: Node tag text -> [Node tag text] -> [Node tag text] -> Path tag text -> Cursor tag text -- | The currently selected content. current :: Cursor tag text -> Node tag text -- | Siblings on the left, closest first. lefts :: Cursor tag text -> [Node tag text] -- | Siblings on the right, closest first. rights :: Cursor tag text -> [Node tag text] -- | The contexts of the parent elements of this location. parents :: Cursor tag text -> Path tag text type Path tag text = [([Node tag text], Tag tag text, [Node tag text])] -- | A cursor for the given content. fromTree :: Node tag text -> Cursor tag text -- | The location of the first tree in a forest. fromForest :: [Node tag text] -> Maybe (Cursor tag text) -- | Computes the forest containing this location. toForest :: Cursor tag text -> [Node tag text] -- | Computes the tree containing this location. toTree :: Cursor tag text -> Node tag text -- | The parent of the given location. parent :: Cursor tag text -> Maybe (Cursor tag text) -- | The top-most parent of the given location. root :: Cursor tag text -> Cursor tag text -- | The child with the given index (starting from 0). getChild :: Int -> Cursor tag text -> Maybe (Cursor tag text) -- | The first child of the given location. firstChild :: Cursor tag text -> Maybe (Cursor tag text) -- | The last child of the given location. lastChild :: Cursor tag text -> Maybe (Cursor tag text) -- | The left sibling of the given location. left :: Cursor tag text -> Maybe (Cursor tag text) -- | The right sibling of the given location. right :: Cursor tag text -> Maybe (Cursor tag text) -- | The next position in a left-to-right depth-first traversal of a -- document: either the first child, right sibling, or the right sibling -- of a parent that has one. nextDF :: Cursor tag text -> Maybe (Cursor tag text) -- | The first child that satisfies a predicate. findChild :: (Cursor tag text -> Bool) -> Cursor tag text -> Maybe (Cursor tag text) -- | Find the next left sibling that satisfies a predicate. findLeft :: (Cursor tag text -> Bool) -> Cursor tag text -> Maybe (Cursor tag text) -- | Find the next right sibling that satisfies a predicate. findRight :: (Cursor tag text -> Bool) -> Cursor tag text -> Maybe (Cursor tag text) -- | Perform a depth first search for a descendant that satisfies the given -- predicate. findRec :: (Cursor tag text -> Bool) -> Cursor tag text -> Maybe (Cursor tag text) -- | Are we at the top of the document? isRoot :: Cursor tag text -> Bool -- | Are we at the left end of the the document? isFirst :: Cursor tag text -> Bool -- | Are we at the right end of the document? isLast :: Cursor tag text -> Bool -- | Are we at the bottom of the document? isLeaf :: Cursor tag text -> Bool -- | Do we have a parent? isChild :: Cursor tag text -> Bool -- | Do we have children? hasChildren :: Cursor tag text -> Bool -- | Get the node index inside the sequence of children getNodeIndex :: Cursor tag text -> Int -- | Change the current content. setContent :: Node tag text -> Cursor tag text -> Cursor tag text -- | Modify the current content. modifyContent :: (Node tag text -> Node tag text) -> Cursor tag text -> Cursor tag text -- | Modify the current content. modifyContentList :: (Node tag text -> [Node tag text]) -> Cursor tag text -> Maybe (Cursor tag text) -- | Modify the current content, allowing for an effect. modifyContentM :: (Monad m) => (Node tag text -> m (Node tag text)) -> Cursor tag text -> m (Cursor tag text) -- | Insert content to the left of the current position. insertLeft :: Node tag text -> Cursor tag text -> Cursor tag text -- | Insert content to the right of the current position. insertRight :: Node tag text -> Cursor tag text -> Cursor tag text -- | Insert content to the left of the current position. insertManyLeft :: [Node tag text] -> Cursor tag text -> Cursor tag text -- | Insert content to the right of the current position. insertManyRight :: [Node tag text] -> Cursor tag text -> Cursor tag text -- | Insert content as the first child of the current position. insertFirstChild :: Node tag text -> Cursor tag text -> Maybe (Cursor tag text) -- | Insert content as the first child of the current position. insertLastChild :: Node tag text -> Cursor tag text -> Maybe (Cursor tag text) -- | Insert content as the first child of the current position. insertManyFirstChild :: [Node tag text] -> Cursor tag text -> Maybe (Cursor tag text) -- | Insert content as the first child of the current position. insertManyLastChild :: [Node tag text] -> Cursor tag text -> Maybe (Cursor tag text) -- | Insert content to the left of the current position. The new content -- becomes the current position. insertGoLeft :: Node tag text -> Cursor tag text -> Cursor tag text -- | Insert content to the right of the current position. The new content -- becomes the current position. insertGoRight :: Node tag text -> Cursor tag text -> Cursor tag text -- | Remove the content on the left of the current position, if any. removeLeft :: Cursor tag text -> Maybe (Node tag text, Cursor tag text) -- | Remove the content on the right of the current position, if any. removeRight :: Cursor tag text -> Maybe (Node tag text, Cursor tag text) -- | Remove the current element. The new position is the one on the left. removeGoLeft :: Cursor tag text -> Maybe (Cursor tag text) -- | Remove the current element. The new position is the one on the right. removeGoRight :: Cursor tag text -> Maybe (Cursor tag text) -- | Remove the current element. The new position is the parent of the old -- position. removeGoUp :: Cursor tag text -> Maybe (Cursor tag text) instance (Show tag, Show text) => Show (Cursor tag text) instance (Show tag, Show text) => Show (Tag tag text) -- | This module provides functions to format a tree structure or SAX -- stream as UTF-8 encoded XML. module Text.XML.Expat.Format -- | Format document with <?xml.. header - lazy variant that returns -- lazy ByteString. format :: (GenericXMLString tag, GenericXMLString text) => Node tag text -> ByteString -- | Format document with <?xml.. header - strict variant that returns -- strict ByteString. format' :: (GenericXMLString tag, GenericXMLString text) => Node tag text -> ByteString -- | Format XML node with no header - lazy variant that returns lazy -- ByteString. formatNode :: (GenericXMLString tag, GenericXMLString text) => Node tag text -> ByteString -- | Format XML node with no header - strict variant that returns strict -- ByteString. formatNode' :: (GenericXMLString tag, GenericXMLString text) => Node tag text -> ByteString -- | DEPRECATED: Renamed to format. formatTree :: (GenericXMLString tag, GenericXMLString text) => Node tag text -> ByteString -- | DEPRECATED: Renamed to format'. formatTree' :: (GenericXMLString tag, GenericXMLString text) => Node tag text -> ByteString xmlHeader :: ByteString -- | Flatten a tree structure into SAX events, monadic version. treeToSAX :: (GenericXMLString tag, GenericXMLString text, Monoid text, NodeClass n c, Functor c) => n c tag text -> c (SAXEvent tag text) -- | Format SAX events with no header - lazy variant that returns lazy -- ByteString. formatSAX :: (GenericXMLString tag, GenericXMLString text) => [SAXEvent tag text] -> ByteString -- | Format SAX events with no header - strict variant that returns strict -- ByteString. formatSAX' :: (GenericXMLString tag, GenericXMLString text) => [SAXEvent tag text] -> ByteString -- | Make the output prettier by adding indentation. indent :: (GenericXMLString tag, GenericXMLString text) => Int -> Node tag text -> Node tag text -- | Make the output prettier by adding indentation, specifying initial -- indent. indent_ :: (GenericXMLString tag, GenericXMLString text) => Int -> Int -> Node tag text -> Node tag text -- | This module ported from Text.XML.Light.Proc module Text.XML.Expat.Proc -- | Select only the elements from a list of XML content. onlyElems :: [Node tag text] -> [Node tag text] -- | Select only the text from a list of XML content. onlyText :: [Node tag text] -> [text] -- | Find all immediate children with the given name. findChildren :: (GenericXMLString tag) => tag -> Node tag text -> [Node tag text] -- | Filter all immediate children wrt a given predicate. filterChildren :: (Node tag text -> Bool) -> Node tag text -> [Node tag text] -- | Filter all immediate children wrt a given predicate over their names. filterChildrenName :: (tag -> Bool) -> Node tag text -> [Node tag text] -- | Find an immediate child with the given name. findChild :: (GenericXMLString tag) => tag -> Node tag text -> Maybe (Node tag text) -- | Find an immediate child with the given name. filterChild :: (Node tag text -> Bool) -> Node tag text -> Maybe (Node tag text) -- | Find an immediate child with name matching a predicate. filterChildName :: (tag -> Bool) -> Node tag text -> Maybe (Node tag text) -- | Find the left-most occurrence of an element matching given name. findElement :: (GenericXMLString tag) => tag -> Node tag text -> Maybe (Node tag text) -- | Filter the left-most occurrence of an element wrt. given predicate. filterElement :: (Node tag text -> Bool) -> Node tag text -> Maybe (Node tag text) -- | Filter the left-most occurrence of an element wrt. given predicate. filterElementName :: (tag -> Bool) -> Node tag text -> Maybe (Node tag text) -- | Find all non-nested occurances of an element. (i.e., once we have -- found an element, we do not search for more occurances among the -- element's children). findElements :: (GenericXMLString tag) => tag -> Node tag text -> [Node tag text] -- | Find all non-nested occurrences of an element wrt. given predicate. -- (i.e., once we have found an element, we do not search for more -- occurances among the element's children). filterElements :: (Node tag text -> Bool) -> Node tag text -> [Node tag text] -- | Find all non-nested occurences of an element wrt a predicate over -- element names. (i.e., once we have found an element, we do not search -- for more occurances among the element's children). filterElementsName :: (tag -> Bool) -> Node tag text -> [Node tag text] -- | A variant of Node in which Element nodes have an annotation of -- any type, and some concrete functions that annotate with the XML parse -- location. -- -- The names conflict with those in Tree so you must use qualified -- import if you want to use both modules. module Text.XML.Expat.Annotated -- | Annotated variant of the tree representation of the XML document. data NodeG a c tag text Element :: !tag -> ![(tag, text)] -> c (NodeG a c tag text) -> a -> NodeG a c tag text eName :: NodeG a c tag text -> !tag eAttributes :: NodeG a c tag text -> ![(tag, text)] eChildren :: NodeG a c tag text -> c (NodeG a c tag text) eAnn :: NodeG a c tag text -> a Text :: !text -> NodeG a c tag text -- | A pure Node that uses a list as its container type. type Node a = NodeG a [] -- | Type shortcut for attributes type Attributes tag text = [(tag, text)] -- | Type shortcut for a single annotated node with unqualified tag names -- where tag and text are the same string type type UNode a text = Node a text text -- | Type shortcut for attributes with unqualified names where tag and text -- are the same string type. type UAttributes text = Attributes text text -- | Type shortcut for a single annotated node, annotated with parse -- location type LNode tag text = Node XMLParseLocation tag text -- | Type shortcut for a single node with unqualified tag names where tag -- and text are the same string type, annotated with parse location type ULNode text = LNode text text -- | Extract all text content from inside a tag into a single string, -- including any text contained in children. textContent :: (NodeClass n [], Monoid text) => n [] tag text -> text -- | Is the given node an element? isElement :: (NodeClass n c) => n c tag text -> Bool -- | Is the given node a tag with the given name? isNamed :: (NodeClass n c, Eq tag) => tag -> n c tag text -> Bool -- | Is the given node text? isText :: (NodeClass n c) => n c tag text -> Bool -- | Get the name of this node if it's an element, return empty string -- otherwise. getName :: (NodeClass n c, Monoid tag) => n c tag text -> tag -- | Get the attributes of a node if it's an element, return empty list -- otherwise. getAttributes :: (NodeClass n c) => n c tag text -> [(tag, text)] -- | Get the value of the attribute having the specified name. getAttribute :: (NodeClass n c, GenericXMLString tag) => n c tag text -> tag -> Maybe text -- | Get children of a node if it's an element, return empty list -- otherwise. getChildren :: (NodeClass n c) => n c tag text -> c (n c tag text) -- | Modify name if it's an element, no-op otherwise. modifyName :: (NodeClass n c) => (tag -> tag) -> n c tag text -> n c tag text -- | Modify attributes if it's an element, no-op otherwise. modifyAttributes :: (NodeClass n c) => ([(tag, text)] -> [(tag, text)]) -> n c tag text -> n c tag text -- | Set the value of the attribute with the specified name to the value, -- overwriting the first existing attribute with that name if present. setAttribute :: (Eq tag, NodeClass n c, GenericXMLString tag) => tag -> text -> n c tag text -> n c tag text -- | Delete the first attribute matching the specified name. deleteAttribute :: (Eq tag, NodeClass n c, GenericXMLString tag) => tag -> n c tag text -> n c tag text -- | setAttribute if Just, deleteAttribute if Nothing. alterAttribute :: (Eq tag, NodeClass n c, GenericXMLString tag) => tag -> Maybe text -> n c tag text -> n c tag text -- | Modify children (non-recursively) if it's an element, no-op otherwise. modifyChildren :: (NodeClass n c) => (c (n c tag text) -> c (n c tag text)) -> n c tag text -> n c tag text -- | Map all tags (both tag names and attribute names) recursively. mapAllTags :: (NodeClass n c) => (tag -> tag') -> n c tag text -> n c tag' text -- | Convert an annotated tree (Annotated module) into a -- non-annotated tree (Tree module). Needed, for example, when you -- format your tree to XML, since format takes a -- non-annotated tree. unannotate :: (Functor c) => NodeG a c tag text -> NodeG c tag text -- | Modify this node's annotation (non-recursively) if it's an element, -- otherwise no-op. modifyAnnotation :: (a -> a) -> Node a tag text -> Node a tag text -- | Modify this node's annotation and all its children recursively if it's -- an element, otherwise no-op. mapAnnotation :: (a -> b) -> Node a tag text -> Node b tag text -- | A qualified name. -- -- Qualified names have two parts, a prefix and a local part. The local -- part is the name of the tag. The prefix scopes that name to a -- particular group of legal tags. -- -- The prefix will usually be associated with a namespace URI. This is -- usually achieved by using xmlns attributes to bind prefixes to URIs. data QName text QName :: Maybe text -> !text -> QName text qnPrefix :: QName text -> Maybe text qnLocalPart :: QName text -> !text -- | Type shortcut for a single annotated node where qualified names are -- used for tags type QNode a text = Node a (QName text) text -- | Type shortcut for attributes with qualified names type QAttributes text = Attributes (QName text) text -- | Type shortcut for a single node where qualified names are used for -- tags, annotated with parse location type QLNode text = LNode (QName text) text toQualified :: (NodeClass n c, GenericXMLString text) => n c text text -> n c (QName text) text fromQualified :: (NodeClass n c, GenericXMLString text) => n c (QName text) text -> n c text text -- | A namespace-qualified tag. -- -- NName has two components, a local part and an optional namespace. The -- local part is the name of the tag. The namespace is the URI -- identifying collections of declared tags. Tags with the same local -- part but from different namespaces are distinct. Unqualified tags are -- those with no namespace. They are in the default namespace, and all -- uses of an unqualified tag are equivalent. data NName text NName :: Maybe text -> !text -> NName text nnNamespace :: NName text -> Maybe text nnLocalPart :: NName text -> !text -- | Type shortcut for a single annotated node where namespaced names are -- used for tags type NNode text a = Node a (NName text) text -- | Type shortcut for attributes with namespaced names type NAttributes text = Attributes (NName text) text -- | Type shortcut for a single node where namespaced names are used for -- tags, annotated with parse location type NLNode text = LNode (NName text) text -- | Make a new NName from a prefix and localPart. mkNName :: text -> text -> NName text -- | Make a new NName with no prefix. mkAnNName :: text -> NName text toNamespaced :: (NodeClass n c, GenericXMLString text, Ord text, Show text, Functor c) => n c (QName text) text -> n c (NName text) text fromNamespaced :: (NodeClass n c, GenericXMLString text, Ord text, Functor c) => n c (NName text) text -> n c (QName text) text xmlnsUri :: (GenericXMLString text) => text xmlns :: (GenericXMLString text) => text data ParserOptions tag text ParserOptions :: Maybe Encoding -> Maybe (tag -> Maybe text) -> ParserOptions tag text -- | The encoding parameter, if provided, overrides the document's encoding -- declaration. parserEncoding :: ParserOptions tag text -> Maybe Encoding -- | If provided, entity references (i.e. &nbsp; and friends) -- will be decoded into text using the supplied lookup function entityDecoder :: ParserOptions tag text -> Maybe (tag -> Maybe text) defaultParserOptions :: ParserOptions tag text -- | Encoding types available for the document encoding. data Encoding ASCII :: Encoding UTF8 :: Encoding UTF16 :: Encoding ISO88591 :: Encoding -- | 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. parse :: (GenericXMLString tag, GenericXMLString text) => ParserOptions tag text -> ByteString -> (LNode tag text, Maybe XMLParseError) -- | Strictly parse XML to tree. Returns error message or valid parsed -- tree. parse' :: (GenericXMLString tag, GenericXMLString text) => ParserOptions tag text -> ByteString -> Either XMLParseError (LNode tag text) -- | Parse error, consisting of message text and error location data XMLParseError XMLParseError :: String -> XMLParseLocation -> XMLParseError -- | Specifies a location of an event within the input text data XMLParseLocation XMLParseLocation :: Int64 -> Int64 -> Int64 -> Int64 -> XMLParseLocation -- | Line number of the event xmlLineNumber :: XMLParseLocation -> Int64 -- | Column number of the event xmlColumnNumber :: XMLParseLocation -> Int64 -- | Byte index of event from start of document xmlByteIndex :: XMLParseLocation -> Int64 -- | The number of bytes in the event xmlByteCount :: XMLParseLocation -> Int64 -- | Lazily parse XML to tree. In the event of an error, throw -- XMLParseException. -- -- parseThrowing can throw an exception from pure code, which is -- generally a bad way to handle errors, because Haskell's lazy -- evaluation means it's hard to predict where it will be thrown from. -- However, it may be acceptable in situations where it's not expected -- during normal operation, depending on the design of your program. parseThrowing :: (GenericXMLString tag, GenericXMLString text) => ParserOptions tag text -> ByteString -> LNode tag text -- | An exception indicating an XML parse error, used by the -- ..Throwing variants. data XMLParseException XMLParseException :: XMLParseError -> XMLParseException data SAXEvent tag text StartElement :: tag -> [(tag, text)] -> SAXEvent tag text EndElement :: tag -> SAXEvent tag text CharacterData :: text -> SAXEvent tag text FailDocument :: XMLParseError -> SAXEvent tag text -- | A lower level function that lazily converts a SAX stream into a tree -- structure. Variant that takes annotations for start tags. saxToTree :: (GenericXMLString tag) => [(SAXEvent tag text, a)] -> (Node a tag text, Maybe XMLParseError) -- | An abstraction for any string type you want to use as xml text (that -- is, attribute values or element text content). If you want to use a -- new string type with hexpat, you must make it an instance of -- GenericXMLString. class (Monoid s, Eq s) => GenericXMLString s gxNullString :: (GenericXMLString s) => s -> Bool gxToString :: (GenericXMLString s) => s -> String gxFromString :: (GenericXMLString s) => String -> s gxFromChar :: (GenericXMLString s) => Char -> s gxHead :: (GenericXMLString s) => s -> Char gxTail :: (GenericXMLString s) => s -> s gxBreakOn :: (GenericXMLString s) => Char -> s -> (s, s) gxFromCStringLen :: (GenericXMLString s) => CStringLen -> IO s gxToByteString :: (GenericXMLString s) => s -> ByteString eAttrs :: Node a tag text -> [(tag, text)] -- | DEPRECATED: Use parse instead. -- -- Lazily parse XML to SAX events. In the event of an error, FailDocument -- is the last element of the output list. Deprecated in favour of new -- parse parseSAX :: (GenericXMLString tag, GenericXMLString text) => Maybe Encoding -> ByteString -> [SAXEvent tag text] -- | DEPRECATED: Use parseThrowing instead. -- -- Lazily parse XML to SAX events. In the event of an error, throw -- XMLParseException. parseSAXThrowing :: (GenericXMLString tag, GenericXMLString text) => Maybe Encoding -> ByteString -> [SAXEvent tag text] -- | DEPRECATED: Use parseLocations instead. -- -- A variant of parseSAX that gives a document location with each SAX -- event. parseSAXLocations :: (GenericXMLString tag, GenericXMLString text) => Maybe Encoding -> ByteString -> [(SAXEvent tag text, XMLParseLocation)] -- | DEPRECATED: Used parseLocationsThrowing instead. -- -- A variant of parseSAX that gives a document location with each SAX -- event. In the event of an error, throw XMLParseException. parseSAXLocationsThrowing :: (GenericXMLString tag, GenericXMLString text) => Maybe Encoding -> ByteString -> [(SAXEvent tag text, XMLParseLocation)] -- | DEPRECATED: Use parse instead. -- -- 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 :: (GenericXMLString tag, GenericXMLString text) => Maybe Encoding -> ByteString -> (LNode tag text, Maybe XMLParseError) -- | DEPRECATED: use parse instead. -- -- Strictly parse XML to tree. Returns error message or valid parsed -- tree. parseTree' :: (GenericXMLString tag, GenericXMLString text) => Maybe Encoding -> ByteString -> Either XMLParseError (LNode tag text) -- | DEPRECATED: use parseThrowing instead -- -- Lazily parse XML to tree. In the event of an error, throw -- XMLParseException. parseTreeThrowing :: (GenericXMLString tag, GenericXMLString text) => Maybe Encoding -> ByteString -> LNode tag text instance (Functor c, List c) => NodeClass (NodeG a) c instance (NFData tag, NFData text, NFData a) => NFData (NodeG a [] tag text) instance (Eq tag, Eq text, Eq a) => Eq (NodeG a [] tag text) instance (Show tag, Show text, Show a) => Show (NodeG a [] tag text)