Hi,

I think this is just a stupid arrow question. Still I cannot find
where my mistake is located.

Suppose I have a simple xml document I want to process with HXT:
<root>
  <elem>
   <sub />
   <risub>text</risub>
  </elem>
</root>

After extracting <elem> I want to duplicate the children trees with
the arrow operator (&&&) and process them to get each sub element,
like I try in treMe2.

Below the example code. While I can get each sub element with tryMe
and tryMe1, tryMe2 will produce a []. Instead I want something like
tryMe3. I think I'm missing something stupid but right now I just feel
stupidly blind.

Thanks for your help,

Andrea


import Text.XML.HXT.Arrow

xml = "<root><elem><sub /><risub>text</risub></elem></root>"

tryMe = runLA arrow []
    where arrow = constA xml >>> xread 
                  >>> 
                  deep (hasName "elem") >>> getChildren 
                  >>> 
                  (hasName "risub" >>> getChildren >>> getText)

tryMe1 = runLA arrow []
    where arrow = constA xml >>> xread 
                  >>> 
                  deep (hasName "elem") >>> getChildren 
                  >>> 
                  (hasName "sub" >>> withDefault (getChildren >>> getText) 
"ciao")

tryMe2 = runLA arrow []
    where arrow = constA xml >>> xread 
                  >>> 
                  deep (hasName "elem") >>> getChildren 
                  >>> 
                  (hasName "sub" >>> withDefault (getChildren >>> getText) 
"ciao")
                  &&&
                  (hasName "risub" >>> getChildren >>> getText)

tryMe3 = runLA arrow []
    where arrow = constA xml >>> xread 
                  >>> 
                  constA "first"
                  &&&
                  constA "second"

The output:

*test> tryMe
["text"]
*test> tryMe1
["ciao"]
*test> tryMe2
[]
*test> tryMe3
[("first","second")]
*test> 
_______________________________________________
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe

Reply via email to