Skip to content

Instantly share code, notes, and snippets.

@nbogie
Created March 23, 2011 23:04
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save nbogie/884223 to your computer and use it in GitHub Desktop.
Save nbogie/884223 to your computer and use it in GitHub Desktop.
A demonstration of a problem calling showattr in HaXml
module Main where
import Text.XML.HaXml
import Text.XML.HaXml.Posn
main :: IO ()
main = processXmlWith (hexagrams `o` tag "IChing")
hexagrams :: Content Posn -> [Content Posn]
hexagrams = html [ hbody [htable [rows `o` children `with` ( tag "hexagram")] ] ]
rows :: Content Posn -> [Content Posn]
rows f =
let
nodes = keep /> attr "ver" /> txt
versions = keep /> attr "ver" /> showattr "ver" -- bails
in hrow [hcol [versions]] f
-- Runtime error:
-- bugdemo.hs: src/Text/XML/HaXml/Combinators.hs:(136,0)-(137,79):
-- Non-exhaustive patterns in function find
--
-- code in question (I think)
-- http://hackage.haskell.org/packages/archive/HaXml/1.20.2/doc/html/src/Text-XML-HaXml-Combinators.html#find
--
-- find :: String -> (String->CFilter i) -> CFilter i
-- find key cont c@(CElem (Elem _ as _) _) = cont (show (lookfor key as)) c
-- where lookfor x = fromMaybe (error ("missing attribute: "++show x)) . lookup x
-- -- 'lookfor' has the more general type :: (Eq a,Show a) => a -> [(a,b)] -> b
--
-- HaXml: Latest version installed: 1.20.2
-- input document
{-
<?xml version="1.0"?>
<IChing>
<hexagram>
<number>1</number>
<name ver="1.1">Ch'ien</name>
</hexagram>
<hexagram>
<number>2</number>
<name ver="2.2">K'un</name>
</hexagram>
</IChing>
-}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment