]> gitweb.michael.orlitzky.com - dead/htsn.git/blob - src/TSN/Xml.hs
Add more code comments.
[dead/htsn.git] / src / TSN / Xml.hs
1 -- | Minimal XML functionality needed to parse each document's
2 -- XML_File_ID.
3 --
4 module TSN.Xml (
5 parse_xmlfid,
6 xml_prologue )
7 where
8
9 import Data.Maybe (listToMaybe, mapMaybe)
10 import Text.Read (readMaybe)
11 import Text.XML.HXT.Core (
12 (>>>),
13 (/>),
14 getChildren,
15 getText,
16 hasName,
17 runLA,
18 xreadDoc )
19
20 -- | A tiny parser written in HXT to extract the "XML_File_ID" element
21 -- from a document.
22 parse_xmlfid :: String -> Maybe Integer
23 parse_xmlfid =
24 listToMaybe . mapMaybe readMaybe . parse
25 where
26 parse :: String -> [String]
27 parse =
28 runLA (xreadDoc
29 >>> hasName "message"
30 /> hasName "XML_File_ID"
31 >>> getChildren
32 >>> getText)
33
34
35 -- | The opening "tag" for the XML prologue.
36 xml_prologue :: String
37 xml_prologue = "<?xml "