(">>>" is my GHCi prompt, might be a bit confusing for an arrow example.)On Tue, Jan 1, 2013 at 2:05 AM, [email protected] < [email protected]> wrote: > Use arrow notation and zeroArrow, like so: > > {-# LANGUAGE Arrows #-} > import Text.XML.HXT.Core > getA = > hasName "a" >>> proc elem -> do > text <- getText <<< getChildren -< elem > if text == "Hello Two!" > then getAttrValue "href" -< elem > else zeroArrow -< () > > >>> runX $ readString [] "<html><a href='example.com/somelink.html'>Hello > One!</a><a href='example.com/anotherlink.html'>Hello Two!</a></html>" >>> > deep getA > ["example.com/anotherlink.html"] > > > > On Mon, Dec 31, 2012 at 3:36 PM, Mateusz Kowalczyk < > [email protected]> wrote: > >> Hello, >> I'm not sure if this is the right place to ask this but here goes. >> >> I'm currently working with HXT and I quite like it. There's one issue I >> can't solve (at least now without some dirty, dirty hacking) and I'm >> sure it's fairly simple. >> >> Consider the following mark-up >> >> <a href="example.com/somelink.**html >> <http://example.com/somelink.html>">Hello >> One!</a> >> <a >> href="example.com/anotherlink.**html<http://example.com/anotherlink.html>">Hello >> Two!</a> >> >> Now, what I'm trying to achieve is to get the href based on the text. I >> can test for what the text is by traversing <a>s, then using the >> getChildren >>> getText arrow. What I can't figure out is how to check >> the text and then get the href as by the time I get to the text, I'll >> further down the tree! >> >> I imagine it would look something along the lines of >> (getChildren >>> getText <?*> "Hello Two") `guards` getAttrValue >> "href". <?*> is just a random operator I made up for illustration >> purposes that works as a predicate over arrows. >> >> Is this the right approach? Is there a built-in that already does what I >> want? It >> seems like a common task... >> >> Mateusz Kowalczyk >> >> ______________________________**_________________ >> Haskell-Cafe mailing list >> [email protected] >> http://www.haskell.org/**mailman/listinfo/haskell-cafe<http://www.haskell.org/mailman/listinfo/haskell-cafe> >> > >
_______________________________________________ Haskell-Cafe mailing list [email protected] http://www.haskell.org/mailman/listinfo/haskell-cafe
