Extracting Values from a Subtree

荒凉一梦 提交于 2019-12-04 06:58:17

doc is not what you thought it is. It has type IOStateArrow s b XmlTree. You really should read your guide again, all you want to know was concluded under the title "Avoiding IO".

Arrows are basically functions. SomeArrow a b can be considered as a generalized/specialized function of type a -> b. >>> and other operators in the scope are for arrow composition, similar to function composition. Your books has type [XmlTree] so it's not an arrow and cannot be composed with arrows. What fulfills your needs is runLA, it transforms an arrow like node "tag" to a normal function:

module Main where

import           Text.XML.HXT.Core

main = do
  html <- readFile "test.xml"
  let doc = readString [withValidate yes, withParseHTML no, withWarnings no] html
  books <- runX $ doc >>> node "book"
  -- runLA (node "cost" /> getText) :: XmlTree -> [String]
  let costs = books >>= runLA (node "cost" /> getText)
  print costs

node tag = multi (hasName tag)
标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!