Module XMLParser defines the low-level interface to the parser.
parseDocument :: String -> [XMLEvent] parseInstance :: String -> [XMLEvent]
parseInstance parses an XML instance into a list of events. parseDocument does the same, but parses the document prolog (optional XML and DOCTYPE declarations) as well. XMLEvent is defined in XMLParse.hs as:
type Name = String
data XMLEvent =
StartEvent Name [(Name,String)] -- start-tag
| EmptyEvent Name [(Name,String)] -- empty element
| EndEvent Name -- end-tag
| TextEvent String -- character data
| PIEvent Name String -- processing instruction
| GERefEvent Name -- general entity reference
| CommentEvent String -- comment
| ErrorEvent String -- error report
This provides a ``SAX-like'' interface, or rather the FP equivalent of SAX. Instead of invoking callback methods on a handler object, the parser returns a (lazy) list of events.
parseInstance is most usefully composed with
buildTree :: [XMLEvent] -> Tree XMLNode
defined in module TreeBuild. This module also defines the converse operation,
serializeTree :: Tree XMLNode -> [XMLEvent]
These are not inverses -- serialize . build is not the identity -- but they should satisfy
build . serialize . build == build serialize . build . serialize == serialize