hxt

Extracting Values from a Subtree

荒凉一梦 提交于 2019-12-04 06:58:17
I am parsing an XML file with HXT and I am trying to break up some of the node extraction into modular pieces (I have been using this as my guide ). Unfortunately, I cannot figure out how to apply some of the selectors once I do the first level parsing. import Text.XML.HXT.Core let node tag = multi (hasName tag) xml <- readFile "test.xml" let doc = readString [withValidate yes, withParseHTML no, withWarnings no] xml books <- runX $ doc >>> node "book" I see that books has a type [XmlTree] :t books books :: [XmlTree] Now I would like to get the first element of books and then extract some

Haskell HXT for extracting a list of values

佐手、 提交于 2019-11-30 20:56:33
I'm trying to figure my way through HXT with XPath and arrows at the same time and I'm completely stuck on how to think through this problem. I've got the following HTML: <div> <div class="c1">a</div> <div class="c2">b</div> <div class="c3">123</div> <div class="c4">234</div> </div> which I've extracted into an HXT XmlTree. What I'd like to do is define a function (I think?): getValues :: [String] -> IOSArrow Xmltree [(String, String)] Which, if used as getValues ["c1", "c2", "c3", "c4"] , will get me: [("c1", "a"), ("c2", "b"), ("c3", "123"), ("c4", "234")] Help please? Here's one approach

Running Haskell HXT outside of IO?

て烟熏妆下的殇ゞ 提交于 2019-11-30 08:10:30
All the examples I've seen so far using the Haskell XML toolkit, HXT, uses runX to execute the parser. runX runs inside the IO monad. Is there a way of using this XML parser outside of IO? Seems to be a pure operation to me, don't understand why I'm forced to be inside IO. Travis Brown You can use HXT's xread along with runLA to parse an XML string outside of IO . xread has the following type: xread :: ArrowXml a => a String XmlTree This means you can compose it with any arrow of type (ArrowXml a) => a XmlTree Whatever to get an a String Whatever . runLA is like runX , but for things of type

Running Haskell HXT outside of IO?

廉价感情. 提交于 2019-11-29 10:50:02
问题 All the examples I've seen so far using the Haskell XML toolkit, HXT, uses runX to execute the parser. runX runs inside the IO monad. Is there a way of using this XML parser outside of IO? Seems to be a pure operation to me, don't understand why I'm forced to be inside IO. 回答1: You can use HXT's xread along with runLA to parse an XML string outside of IO . xread has the following type: xread :: ArrowXml a => a String XmlTree This means you can compose it with any arrow of type (ArrowXml a) =>