Safe Haskell | Safe-Inferred |
---|---|
Language | Haskell98 |
Text.XML.Expat.SAX
Description
This module provides functions to parse an XML document to a lazy stream of SAX events.
Synopsis
- data Encoding
- data XMLParseError = XMLParseError String XMLParseLocation
- data XMLParseLocation = XMLParseLocation {}
- data ParseOptions tag text = ParseOptions {
- overrideEncoding :: Maybe Encoding
- entityDecoder :: Maybe (tag -> Maybe text)
- data SAXEvent tag text
- = XMLDeclaration text (Maybe text) (Maybe Bool)
- | StartElement tag [(tag, text)]
- | EndElement tag
- | CharacterData text
- | StartCData
- | EndCData
- | ProcessingInstruction text text
- | Comment text
- | FailDocument XMLParseError
- parse :: (GenericXMLString tag, GenericXMLString text) => ParseOptions tag text -> ByteString -> [SAXEvent tag text]
- parseG :: forall tag text l. (GenericXMLString tag, GenericXMLString text, List l) => ParseOptions tag text -> l ByteString -> l (SAXEvent tag text)
- parseLocations :: (GenericXMLString tag, GenericXMLString text) => ParseOptions tag text -> ByteString -> [(SAXEvent tag text, XMLParseLocation)]
- parseLocationsG :: forall tag text l. (GenericXMLString tag, GenericXMLString text, List l) => ParseOptions tag text -> l ByteString -> l (SAXEvent tag text, XMLParseLocation)
- parseLocationsThrowing :: (GenericXMLString tag, GenericXMLString text) => ParseOptions tag text -> ByteString -> [(SAXEvent tag text, XMLParseLocation)]
- parseThrowing :: (GenericXMLString tag, GenericXMLString text) => ParseOptions tag text -> ByteString -> [SAXEvent tag text]
- defaultParseOptions :: ParseOptions tag text
- data XMLParseException = XMLParseException XMLParseError
- class (Monoid s, Eq s) => GenericXMLString s where
- gxNullString :: s -> Bool
- gxToString :: s -> String
- gxFromString :: String -> s
- gxFromChar :: Char -> s
- gxHead :: s -> Char
- gxTail :: s -> s
- gxBreakOn :: Char -> s -> (s, s)
- gxFromByteString :: ByteString -> s
- gxToByteString :: s -> ByteString
XML primitives
data XMLParseError Source #
Parse error, consisting of message text and error location
Constructors
XMLParseError String XMLParseLocation |
Instances
Show XMLParseError Source # | |
Defined in Text.XML.Expat.Internal.IO | |
NFData XMLParseError Source # | |
Defined in Text.XML.Expat.Internal.IO Methods rnf :: XMLParseError -> () Source # | |
Eq XMLParseError Source # | |
Defined in Text.XML.Expat.Internal.IO Methods (==) :: XMLParseError -> XMLParseError -> Bool Source # (/=) :: XMLParseError -> XMLParseError -> Bool Source # |
data XMLParseLocation Source #
Specifies a location of an event within the input text
Constructors
XMLParseLocation | |
Fields
|
Instances
Show XMLParseLocation Source # | |
Defined in Text.XML.Expat.Internal.IO | |
NFData XMLParseLocation Source # | |
Defined in Text.XML.Expat.Internal.IO Methods rnf :: XMLParseLocation -> () Source # | |
Eq XMLParseLocation Source # | |
Defined in Text.XML.Expat.Internal.IO Methods (==) :: XMLParseLocation -> XMLParseLocation -> Bool Source # (/=) :: XMLParseLocation -> XMLParseLocation -> Bool Source # |
SAX-style parse
data ParseOptions tag text Source #
Constructors
ParseOptions | |
Fields
|
data SAXEvent tag text Source #
Constructors
XMLDeclaration text (Maybe text) (Maybe Bool) | |
StartElement tag [(tag, text)] | |
EndElement tag | |
CharacterData text | |
StartCData | |
EndCData | |
ProcessingInstruction text text | |
Comment text | |
FailDocument XMLParseError |
Arguments
:: (GenericXMLString tag, GenericXMLString text) | |
=> ParseOptions tag text | Parse options |
-> ByteString | Input text (a lazy ByteString) |
-> [SAXEvent tag text] |
Lazily parse XML to SAX events. In the event of an error, FailDocument is the last element of the output list.
Arguments
:: forall tag text l. (GenericXMLString tag, GenericXMLString text, List l) | |
=> ParseOptions tag text | Parse options |
-> l ByteString | Input text (a lazy ByteString) |
-> l (SAXEvent tag text) |
Parse a generalized list of ByteStrings containing XML to SAX events. In the event of an error, FailDocument is the last element of the output list.
Arguments
:: (GenericXMLString tag, GenericXMLString text) | |
=> ParseOptions tag text | Parse options |
-> ByteString | Input text (a lazy ByteString) |
-> [(SAXEvent tag text, XMLParseLocation)] |
A variant of parseSAX that gives a document location with each SAX event.
Arguments
:: forall tag text l. (GenericXMLString tag, GenericXMLString text, List l) | |
=> ParseOptions tag text | Parse options |
-> l ByteString | Input text (a lazy ByteString) |
-> l (SAXEvent tag text, XMLParseLocation) |
Parse a generalized list of ByteStrings containing XML to SAX events. In the event of an error, FailDocument is the last element of the output list.
parseLocationsThrowing Source #
Arguments
:: (GenericXMLString tag, GenericXMLString text) | |
=> ParseOptions tag text | Optional encoding override |
-> ByteString | Input text (a lazy 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.
Arguments
:: (GenericXMLString tag, GenericXMLString text) | |
=> ParseOptions tag text | Parse options |
-> ByteString | input text (a lazy ByteString) |
-> [SAXEvent tag text] |
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.
defaultParseOptions :: ParseOptions tag text Source #
Variants that throw exceptions
data XMLParseException Source #
An exception indicating an XML parse error, used by the ..Throwing variants.
Constructors
XMLParseException XMLParseError |
Instances
Exception XMLParseException Source # | |
Defined in Text.XML.Expat.SAX Methods toException :: XMLParseException -> SomeException Source # fromException :: SomeException -> Maybe XMLParseException Source # | |
Show XMLParseException Source # | |
Defined in Text.XML.Expat.SAX | |
Eq XMLParseException Source # | |
Defined in Text.XML.Expat.SAX Methods (==) :: XMLParseException -> XMLParseException -> Bool Source # (/=) :: XMLParseException -> XMLParseException -> Bool Source # |
Abstraction of string types
class (Monoid s, Eq s) => GenericXMLString s where Source #
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
.
Methods
gxNullString :: s -> Bool Source #
gxToString :: s -> String Source #
gxFromString :: String -> s Source #
gxFromChar :: Char -> s Source #
gxBreakOn :: Char -> s -> (s, s) Source #
gxFromByteString :: ByteString -> s Source #
gxToByteString :: s -> ByteString Source #