hexml-0.3.3: XML subset DOM parser

Safe HaskellNone
LanguageHaskell2010

Text.XML.Hexml

Description

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

Synopsis

Documentation

data Node Source #

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

Instances

data Attribute Source #

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

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