<div dir="ltr"><div><div><div><div><div><div>Use arrow notation and zeroArrow, like so:<br><br></div>{-# LANGUAGE Arrows #-}<br>import Text.XML.HXT.Core<br>getA =<br> hasName "a" >>> proc elem -> do<br>
text <- getText <<< getChildren -< elem<br> if text == "Hello Two!"<br> then getAttrValue "href" -< elem<br> else zeroArrow -< ()<br><br>>>> runX $ readString [] "<html><a href='<a href="http://example.com/somelink.html">example.com/somelink.html</a>'>Hello One!</a><a href='<a href="http://example.com/anotherlink.html">example.com/anotherlink.html</a>'>Hello Two!</a></html>" >>> deep getA<br>
["<a href="http://example.com/anotherlink.html">example.com/anotherlink.html</a>"]<br><br></div></div></div></div></div></div><div class="gmail_extra"><br><br><div class="gmail_quote">On Mon, Dec 31, 2012 at 3:36 PM, Mateusz Kowalczyk <span dir="ltr"><<a href="mailto:fuuzetsu@fuuzetsu.co.uk" target="_blank">fuuzetsu@fuuzetsu.co.uk</a>></span> wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Hello,<br>
I'm not sure if this is the right place to ask this but here goes.<br>
<br>
I'm currently working with HXT and I quite like it. There's one issue I<br>
can't solve (at least now without some dirty, dirty hacking) and I'm<br>
sure it's fairly simple.<br>
<br>
Consider the following mark-up<br>
<br>
<a href="<a href="http://example.com/somelink.html" target="_blank">example.com/somelink.<u></u>html</a>">Hello One!</a><br>
<a href="<a href="http://example.com/anotherlink.html" target="_blank">example.com/anotherlink.<u></u>html</a>">Hello Two!</a><br>
<br>
Now, what I'm trying to achieve is to get the href based on the text. I<br>
can test for what the text is by traversing <a>s, then using the<br>
getChildren >>> getText arrow. What I can't figure out is how to check<br>
the text and then get the href as by the time I get to the text, I'll<br>
further down the tree!<br>
<br>
I imagine it would look something along the lines of<br>
(getChildren >>> getText <?*> "Hello Two") `guards` getAttrValue<br>
"href". <?*> is just a random operator I made up for illustration<br>
purposes that works as a predicate over arrows.<br>
<br>
Is this the right approach? Is there a built-in that already does what I want? It<br>
seems like a common task...<br>
<br>
Mateusz Kowalczyk<br>
<br>
______________________________<u></u>_________________<br>
Haskell-Cafe mailing list<br>
<a href="mailto:Haskell-Cafe@haskell.org" target="_blank">Haskell-Cafe@haskell.org</a><br>
<a href="http://www.haskell.org/mailman/listinfo/haskell-cafe" target="_blank">http://www.haskell.org/<u></u>mailman/listinfo/haskell-cafe</a><br>
</blockquote></div><br></div>