hexml-0.3.5: XML subset DOM parser

Safe Haskell | Safe-Inferred
Language | Haskell2010

Text.XML.Hexml

Description

A module for fast first-approximation parsing of XML. Note that entities, e.g. `&amp;`, are not expanded.

Synopsis

- data Node
- data Attribute = Attribute {
  - attributeName :: ByteString
  - attributeValue :: ByteString
  }
- parse :: ByteString -> Either ByteString Node
- render :: Node -> ByteString
- location :: Node -> (Int, Int)
- name :: Node -> ByteString
- inner :: Node -> ByteString
- outer :: Node -> ByteString
- attributes :: Node -> [Attribute]
- children :: Node -> [Node]
- contents :: Node -> [Either ByteString Node]
- attributeBy :: Node -> ByteString -> Maybe Attribute
- childrenBy :: Node -> ByteString -> [Node]

# Documentation

data Node Source #

A node in an XML document, created by `parse`, then calling functions such as `children` on that initial `Node`.

#### Instances

Instances details

Show Node Source # |
Instance details Defined in Text.XML.Hexml Methods showsPrec :: Int -> Node -> ShowS Source # show :: Node -> String Source # showList :: [Node] -> ShowS Source #

data Attribute Source #

An XML attribute, comprising of a name and a value. As an example, `hello="world"` would produce `Attribute "hello" "world"`.

Constructors

Attribute |

Fields

- attributeName :: ByteString
- attributeValue :: ByteString

#### Instances

Instances details

Show Attribute Source # |
Instance details Defined in Text.XML.Hexml Methods showsPrec :: Int -> Attribute -> ShowS Source # show :: Attribute -> String Source # showList :: [Attribute] -> ShowS Source #
Eq Attribute Source # |
Instance details Defined in Text.XML.Hexml Methods (==) :: Attribute -> Attribute -> Bool Source # (/=) :: Attribute -> Attribute -> Bool Source #
Ord Attribute Source # |
Instance details Defined in Text.XML.Hexml Methods compare :: Attribute -> Attribute -> Ordering Source # (<) :: Attribute -> Attribute -> Bool Source # (<=) :: Attribute -> Attribute -> Bool Source # (>) :: Attribute -> Attribute -> Bool Source # (>=) :: Attribute -> Attribute -> Bool Source # max :: Attribute -> Attribute -> Attribute Source # min :: Attribute -> Attribute -> Attribute Source #

parse :: ByteString -> Either ByteString Node Source #

Parse a ByteString as an XML document, returning a `Left` error message, or a `Right` document. Note that the returned node will have a `name` of `""`, no `attributes`, and `contents` as per the document. Often the first child will be the `<?xml ... ?>` element. For documents which comprise an XML node and a single root element, use ``children` n !! 1`.

render :: Node -> ByteString Source #

Given a node, rerender it to something with an equivalent parse tree. Mostly useful for debugging - if you want the real source document use `outer` instead.

location :: Node -> (Int, Int) Source #

Find the starting location of a node, the `<` character. The first character will be reported as `(line 1,column 1)`, because thats how error messages typically do it.

name :: Node -> ByteString Source #

Get the name of a node, e.g. `<test />` produces `"test"`.

inner :: Node -> ByteString Source #

Get the inner text, from inside the tag, e.g. `<test />` produces `""` and `<test>hello</test>` produces `"hello"`. The result will have identical layout/spacing to the source document.

outer :: Node -> ByteString Source #

Get the outer text, including the tag itself, e.g. `<test />` produces `"<test />"` and `<test>hello</test>` produces `"<test>hello</test>"`. The result will have identical layout/spacing to the source document.

attributes :: Node -> [Attribute] Source #

Get the attributes of this node.

children :: Node -> [Node] Source #

Get the direct child nodes of this node.

contents :: Node -> [Either ByteString Node] Source #

Get the contents of a node, including both the content strings (as `Left`, never blank) and the direct child nodes (as `Right`). If you only want the child nodes, use `children`.

attributeBy :: Node -> ByteString -> Maybe Attribute Source #

Get the first attribute of this node which has a specific name, if there is one. A more efficient version of:

    attributeBy n s = listToMaybe $ filter (\(Attribute a _) -> a == s $ attributes n

childrenBy :: Node -> ByteString -> [Node] Source #

Get the direct children of this node which have a specific name. A more efficient version of:

    childrenBy p s = filter (\n -> name n == s) $ children p