I am trying to 'preparse' XML with HXT into [XmlTree] once and then reuse this data several times.
Below is my code:
{-# LANGUAGE Arrows, NoMonomorphismRestriction #-} import Text.XML.HXT.Core parseXML = readDocument [ withValidate no , withRemoveWS yes -- throw away formating WS ] atTag tag = deep (isElem >>> hasName tag) data UiWindow = UiWindow { wndName :: String, wndNameLib :: String, wndChildren :: [UiWindow] } deriving (Show) initUiWindow = UiWindow { wndName = "empty", wndNameLib = "", wndChildren = [] } parseDoc docName = runX $ parseXML fileName >>> getWindow where fileName = docName ++ ".xml" getWindow = atTag "Window" >>> proc x -> do libraryItemName <- getAttrValue "libraryItemName" -< x name <- getAttrValue "name" -< x children <- arrIO parseDoc -< libraryItemName returnA -< initUiWindow { wndName = name, wndNameLib = libraryItemName, wndChildren = children} documentName = "DOMDocument.xml" parseRoot = parseXML documentName --runX (parseRoot >>> getWindow ) If I parse beforehand:
λ: x <- runX parseRoot λ: :t x x :: [XmlTree] λ: :t getWindow getWindow :: IOSLA (XIOState ()) XmlTree UiWindow How do I run something like this:
runX $ XYZ(x) >>> getWindow or this:
runX $ XYZ(x) >>> getSomethingElse Allowing me to reuse data in 'x'.
No comments:
Post a Comment