xeno-0.6: A fast event-based XML parser in pure Haskell

Safe Haskell | Safe-Inferred
Language | Haskell2010

Xeno.SAX

Description

SAX parser and API for XML.

Synopsis

- process :: (Monad m, StringLike str) => Process (m ()) -> str -> m ()
- data Process a = Process {
  - openF :: !(ByteString -> a)
  - attrF :: !(ByteString -> ByteString -> a)
  - endOpenF :: !(ByteString -> a)
  - textF :: !(ByteString -> a)
  - closeF :: !(ByteString -> a)
  - cdataF :: !(ByteString -> a)
  }
- class StringLike str where
  - s_index' :: str -> Int -> Word8
  - elemIndexFrom' :: Word8 -> str -> Int -> Maybe Int
  - drop' :: Int -> str -> str
  - substring' :: str -> Int -> Int -> ByteString
  - toBS :: str -> ByteString
- fold :: (s -> ByteString -> s) -> (s -> ByteString -> ByteString -> s) -> (s -> ByteString -> s) -> (s -> ByteString -> s) -> (s -> ByteString -> s) -> (s -> ByteString -> s) -> s -> ByteString -> Either XenoException s
- validate :: StringLike str => str -> Bool
- validateEx :: StringLike str => str -> Bool
- dump :: ByteString -> IO ()
- skipDoctype :: ByteString -> ByteString

# Documentation

process :: (Monad m, StringLike str) => Process (m ()) -> str -> m () Source #

Process events with callbacks in the XML input.

data Process a Source #

Parameters to the `process` function

Constructors

Process |

Fields

- openF :: !(ByteString -> a)

  Open tag.

- attrF :: !(ByteString -> ByteString -> a)

  Tag attribute.

- endOpenF :: !(ByteString -> a)

  End open tag.

- textF :: !(ByteString -> a)

  Text.

- closeF :: !(ByteString -> a)

  Close tag.

- cdataF :: !(ByteString -> a)

  CDATA.

class StringLike str where Source #

Methods

s_index' :: str -> Int -> Word8 Source #

elemIndexFrom' :: Word8 -> str -> Int -> Maybe Int Source #

drop' :: Int -> str -> str Source #

substring' :: str -> Int -> Int -> ByteString Source #

toBS :: str -> ByteString Source #

#### Instances

Instances details

StringLike ByteString Source # |
Instance details Defined in Xeno.SAX Methods s_index' :: ByteString -> Int -> Word8 Source # elemIndexFrom' :: Word8 -> ByteString -> Int -> Maybe Int Source # drop' :: Int -> ByteString -> ByteString Source # substring' :: ByteString -> Int -> Int -> ByteString Source # toBS :: ByteString -> ByteString Source #
StringLike ByteStringZeroTerminated Source # |
Instance details Defined in Xeno.SAX Methods s_index' :: ByteStringZeroTerminated -> Int -> Word8 Source # elemIndexFrom' :: Word8 -> ByteStringZeroTerminated -> Int -> Maybe Int Source # drop' :: Int -> ByteStringZeroTerminated -> ByteStringZeroTerminated Source # substring' :: ByteStringZeroTerminated -> Int -> Int -> ByteString Source # toBS :: ByteStringZeroTerminated -> ByteString Source #

fold Source #

Arguments

:: (s -> ByteString -> s) | Open tag.
-> (s -> ByteString -> ByteString -> s) | Attribute key/value.
-> (s -> ByteString -> s) | End of open tag.
-> (s -> ByteString -> s) | Text.
-> (s -> ByteString -> s) | Close tag.
-> (s -> ByteString -> s) | CDATA.
-> s |
-> ByteString |
-> Either XenoException s |

Fold over the XML input.

validate :: StringLike str => str -> Bool Source #

Parse the XML but return no result, process no events.

N.B.: Only the lexical correctness of the input string is checked, not its XML semantics (e.g. only if tags are well formed, not whether tags are properly closed)

    > :set -XOverloadedStrings
    > validate "<b>"
    True

    > validate "<b"
    False

validateEx :: StringLike str => str -> Bool Source #

Parse the XML and checks tags nesting.

dump :: ByteString -> IO () Source #

Parse the XML and pretty print it to stdout.

skipDoctype :: ByteString -> ByteString Source #

Skip initial DOCTYPE declaration