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