Your SlideShare is downloading. ×
0
Xpath in-lens
Xpath in-lens
Xpath in-lens
Xpath in-lens
Xpath in-lens
Xpath in-lens
Xpath in-lens
Xpath in-lens
Xpath in-lens
Xpath in-lens
Xpath in-lens
Xpath in-lens
Xpath in-lens
Xpath in-lens
Xpath in-lens
Xpath in-lens
Xpath in-lens
Xpath in-lens
Xpath in-lens
Xpath in-lens
Xpath in-lens
Xpath in-lens
Upcoming SlideShare
Loading in...5
×

Thanks for flagging this SlideShare!

Oops! An error has occurred.

×
Saving this for later? Get the SlideShare app to save on your phone or tablet. Read anywhere, anytime – even offline.
Text the download link to your phone
Standard text messaging rates apply

Xpath in-lens

178

Published on

Lens&Prism勉強会 http://connpass.com/event/13929/ の発表資料

Lens&Prism勉強会 http://connpass.com/event/13929/ の発表資料

Published in: Technology
0 Comments
2 Likes
Statistics
Notes
  • Be the first to comment

No Downloads
Views
Total Views
178
On Slideshare
0
From Embeds
0
Number of Embeds
0
Actions
Shares
0
Downloads
0
Comments
0
Likes
2
Embeds 0
No embeds

Report content
Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
No notes for slide

Transcript

  • 1. XPcJ’rh in Lens ElElEF'§i: r (@’rcinc1l<h)
  • 2. E Erififi‘ ° BEIEP ii‘? (@’rc1nc1|<h) - Hos| <e| |’rY>:3‘C$§’ ~ Lens¥EL/ §"? ‘:i“C3l’)73‘lOE’e“/ ia ° C? ZODZl57Z: DOD%%'% 3:? ) L; <a"5lFaEbL/ &"§'! -ac: Haskell ’‘= <? “!? ?-’ mm. .. W iiiiii: I I » 9:22 , xi _ ' ‘_l‘: I=iK(= l»_It iiifilidiiif ~; ;E:1,—, ,=<_ ,2‘
  • 3. l ( o('-_ l l ( Iviolivoling Example -‘). oO(llF§7‘: “fa2Zl73.. .) -‘ . oO(EzoeEE/ ult M ’C“t3§‘§73‘. ..) -‘ . oO(. ..) -‘ . oO(. ..) ) ) - ’-_-‘). oO(EF= fi©‘é7E&3i:7‘5'7b°i: ii§§)J©*§0)‘e7;t2l5.. .) ' ) l -‘ . oO(CL|13"5i’2“iE§"§’i‘3’3i’F§73‘. ..)
  • 4. . 'C'355’V‘<§T. f. http: ./, /ask. fm/ EzoeRyou. /answer/ l275i 7834839 lltfil/ '55 U)'Ci’D)‘J“57ZiL M, ht’tr>: /./ ,asl«. .fm/ EzoeRy0u/ ariswer/ l275i 8042455 7!‘/ H3 5e‘, foTIi; I«2l ‘O ht to : /i-"ask .1‘m/ EzoeRyou/ answer/12754i85U775
  • 5. §'§fi0Di’2"i% 0DiEl3 Hf. ~ h’r’r; :_): [[<Jsl<. fm[feed[Qrofi| e[<USERNAIvlE>. rss 7 E ‘ I-T-F? -Ea “E <__.0_)/ /J7'g3‘f2Es‘z1fi0)E9FE73gfiE57D5 bgL/ _l, <? xm1 ver‘sion= "1.6" encoding= "UTF-8"? ) <rss xm1ns: dc= "http: //purl. or*g/ dc/ elements/1. 1/" ver‘sion= "2.6"> <channe1> <tit1e>Ryou Ezoe (ask. fm/ EzoeRyou) . &#22238;&#31572; </ tit1e> <1inl<>http: // ask. fm/ EzoeRyou</1ink> <descr‘iption>EzoeRyou ' s answers today — Ask. -Fm</ descriptiom <gener‘ator‘>h1:tp: //ask. fm/ </generator‘> <ttl>66</ tt1> <item> <title>&#31S65;&#27713;&#12387;&#1239B; &#30693;&#12387;&#12390;&#124l4;&#12377;, ., <title> <desc ription >&#3Z654;&#21619,'&#12375;&#1238l; &#12358;&#12384;&#l2296; </ descript ion> <pubDate>Fr‘i, 29 May 2015 18:26:03 +00e6</ pubDate> <lin| <>http: //ask. -Fm/ EzoeRyou/ answer/127892627543</ lin| <> <guid isPei"maLink= "tr‘ue">http: //ask. -Fm/ EzoeRyou/ answer/127892627543</ guid> <dc : cr'eat0r‘>EzoeRyou</ dc : cr*ea‘tor*> </ item> <item> <tit1e>&#229@9;&#12365,'&#12394;&#12S08;&#124-89;&#12466;&#12392;&#24375;&#12356;&#12508;
  • 6. Rss0)77r—7y| (: Lfi_é’i) ° / rss/ channel/ ilem (C7/i’7_-A0)—%§b“5§'5 L/ L - / rss/ Channel/ ilem/ ’ri’r| e 73“@’i’ | )| / (As| <0Di%i’Ei’, iF'= -3) ~ / rss/ channel/ ilem/ descriplion 73“2lS§Z (Asl<0Di%élE| §) - / rss/ channel/ ilem/ link DVURL BL/ l,o )Oo. ('—_—‘)El’J'7iJ3‘J. ..
  • 7. XML access in Haskell import Text. XML as XML xml-- conduit findElement : : Element —> Name —> [Element] findElement e name = [ c I NodeElement c <- elementNodes e , e1ementName c = = name ] getcontent : : Element -> Text getcontent e = mconcat [ c I Nodecontent c <- elementNodes e ] main : : IO () main = do doc <— XML . readFile def "EzoeRyou. rss" r'ssPr‘int doc
  • 8. 33% rssPrint : 2 Document —> I0 () rssPrint doc = do let root = documentRoot doc items = do chan <— findElement root "channel" -FindElement chan "item" -ForM_ items $ ¥item -> do T. putStrLn $ mconcat $ map getcontent $ findElement item "link" T. putStrLn $ mconcat :5 map getcontent $ findElement item "title" T. putStrLn $ mconcat $ map getcontent $ -FindElement item "description" putStrLn ""
  • 9. do/ ué: “< Em! -ADTiEi§2mL‘)§0)iah s”€I3f: %E&>/ utwi -*l%lC 7r~7lL/ t§’r‘3Dé:73 fi'l%L/ ‘C5’r‘3’Jc‘:73 ('-_-‘) lSYB Unipla’re? fl7Zf%3l’LlE, to : /ur‘— ieo_t57riabx, lei: JavaScr'pllZl; =v'<5%“ ! J Text. XML DOM—based parsing and rendering. This module requires that all entities be resolved at parsing. If you need recommended module for most uses cases. While many of the clatatypes in this module are simply reexpoited from possibility of unresolved entities. Conversion functions are provided to s For simpler, bidirectional traversal of the DOM tree, see the Text Xr~’lL Cu Data types Us la Document Constructors Document docuiiientlhclague : : Prologue documentRoot : : Element documentEpi1ague : : [Miscellaneous] . », Insta nccs data Prologue . ~ x Constructors Prologue prologuenefore : : [Miscellaneous]
  • 10. Text. XML. Cursor - XPalh5/1”? ??/ i’ ‘/9-7:: —X*635ZalClata‘5§(xm| —conduil) import Text. XML. Cursor -- also in xml-conduit rssCursor : : Document -> IO () rssCursor doc = do let items = fromDocument doc & (element "rss" &/ element "channel" &/ element " item") -ForM_ items $ ¥item —> do T. putStrLn $ mconcat 35 item 519/ element "link" &/ content T. putStrLn $ mconcat $ item 515/ element "title" &/ content T. putStrLn $ mconcat 55 item $/ element "description" &/ content putStrLn "" (&) = flip ($) (GHC—7.lO 73“5baselC§)K)
  • 11. L;73‘L/ ... - L75L‘5/ i‘J’7—‘/ “t‘_"‘6:0D’7I U §§E7a': %‘. i§0)lat IE‘ieL/ /utmo ('-_-‘) lZ/ u722§§El§‘3‘C§? l’l§73‘o l§l: tJavaScrip’rlCl7='<% ! J
  • 12. HaskelllZl: £Lens73“3537': ! import Text. XML. Lens —— xml—lens rssLens : : Document —> 10 () rssLens doc = forM_ (doc". . root . el"rss" . /el"channel" . /el"item") $ ¥item -> do T. putStrLn 55 item“. plate. el"link" . text T. putStrLn 513 item“. plate. el"title" . text T. putStrLn 51% item“. plate. el"description" . text putStrLn ""
  • 13. XIviL0D70t7lZLens7ii§'5 cEl9ii5F'J ! ~ Lens7;t'5 %l$ECDOI'JDSLctl2tiED’C ° lE<§l]‘5l’l. 'C l’_I'. '<l§l’)l’l_Cl/ § ° 7?*_‘73“5 :77‘/ u7“a‘~LensE§l]’J_Cl/ 5 -7?i73‘5 5'7‘/ u72tLens‘&Fa'El$lClE’5_ct73“"C‘§Zo ° 5'7‘/ u7JLens7‘&l§iZ>0D—(: ' ¥li7Z‘_lC%i§? _’. &73“’}‘7'a3<_C5§i: ‘ I, ° u ' ‘I J
  • 14. 7cLfCLens‘}E/ --- ruin. nu--in . ... a F. ... ... ... F.. ... ,. . . (ll-rbi->(I->1!)-islluuun Contro| .Lens. internal. Magma mnw-u iimuiusnaii-iiiaian roiumvov Mmaar->FoIuu->(I- ->1-n loiar0i*Fo1d —‘Vl~>r~>I- InLi| lOi Fou III -nyoi mac: B091)»: ->80-1| manor, lbfifizllvlll-FoId| l—>(n—vlvI->1-= l[) Contro| .Lens. lnternal. Prism Mm“_"m¢_W ControI. Lens. |nternal. PrismTH : .'. "i5ili’1.‘: .'. .‘s’¥. ‘.. ?". 'm'. $2»". ;'é‘“n“. ’3:; §":1'. ';. ”' 2‘-3‘? u. "“'. :§"“. ;.. :.”. :’s. ..""'. '.'. '.. ".". .‘: ’:': i”’ ""_ Control Lens. Interna I . Reflection Control. Lens. lnternal. Review Control. Lens. Internatsetier Control. Lens. |nterna| .TH our vunmi-in to lI~>I]->GoImu u. ».. ... r.. m.u. i-»mm. iiv-inn)-n Con[ro| _Len3_| n[ernaI_Zoom , ‘ fiwgsfi 35 35 35 "" ‘ ‘ H-'- #343 £'. ... ... .. ol. 5. -i--anon-~rmn-nun. » mrmonni-inn? i: :;2:'--"-i. ..s. .'-: ;r. .:-. ..: ;:. ~.: ::; :': ::. ::: :.. ... .,i. m, Control-Lens-Level Control. Lens. Operators . .i. .a l-invun ___‘__ W (_A__)wmm Contro| .Lens. Plated ‘-‘"-, Fg; ;I‘-_'_g-_; '_'= _;‘*. 'g; '_| ;'i--'-° m G: : llnhamI Contro| .Lens. Prism :2 F-«nun-rtomni-n """' '"°"“’”"""" "'°""" . I r. '.i; f“i‘. '31“"Zlt'. '.. §I. '.'l. ii. ... (.. ... i.. ..i "‘ "" Comro| 'Lens'Re| fied T ramm- P/ Film: """'*'°"""'“-°"*"°" "W"-" Control Lens Review n-iuuvmam. ,iu. »ini-». .>ii W. .. , (.. ,., _.[. ..g. ... ... ,_. p,. .,. .,. .., ' ' (‘I-‘Ar-)‘ 1->| .nnninn.2lI. ~iI). >n. vri (5659-)11MonlflllflINI->l. IIlIID~P(l-'l'. l)l""" : $;vP, w;_<3;«‘; .v: ;i_<)E(rEv; r_gEcih; _>_ Control, Lens. Setter 7-E ConlroI. Lens. TH _M__’ I _ m_'j: ;"° Contro| .Lens. Traversa| Contro| .Lens. Tuple -um : smu-nu. mnoinn Timmy! ->noIlIb. vholVI)lli)llINlDl Pnnfrnl I one Tuna
  • 15. LX I3?-iiEE
  • 16. XPa’rh &Lens0D3blfii‘3l§U Iicllk rooi. el"hoge" rool. enlire. el”hoge" el”hoge". plale. el”hage” el”hoge". ..e| ”hage” e| ”hoge". /e| "hage" (T:3iat~>J: zs) el"hoge”. enlire. el"nage" el”hoge". nodes el”hoge”. p|ale. plaie. e|"hage” indexing (el “hoge") . indexO indexing (el”hoge") . indices(<2) I ‘C"oIii sill? / hoge l*‘= l=: L>4> l)l/ — l0D<hoge> / /hoge l*‘= l‘—: L>4> F3‘/ ‘"COD<hoge> hoge/ hage <hoge>(DIEi§0D¥§§‘C‘35§ <hage> hoge/ /nage <hoge>0D§'/ ‘“C¥5‘, %J — | *‘lC35 §<hage> hoge/ * <hoge>CD¥§§E§‘/ “C hoge/ */hage <hoge>0)¥%§§’E‘C‘i5§<hage> hoge[i] l§EOD<hoge> hoge[posilion() <3] <hoge>0D5'E§E2§§E $7E§7'i‘l’)l'l03i’)7J"57Eil, 0D73“7': < F. “/uZl5ZaE'>*T: l,
  • 17. &Z5—C‘CSSt I/0’>"— tl, 50D73“@§ ° CSS—C‘Hll/ lL0DDOl/ l03§§'%7<7:: L5§§J‘R3_c7D7:l: U Egg - JavaScrip’r73"5DOM0D§§Ei%l‘R7J”§0DlC‘6i§l’)l’l_Cl/ § ° Z T) "50Dli573“3El/ A'§'lJL73“E73". D 7T:73"5 Lx? l’U'd§l, (' -_- ‘) . oO(%‘i-3%”t3l¥EXPain722/u"C§| ]'5/uibo 3E%i’9 bl
  • 18. csst i/ J/si—. c:0>sdri~: l'iIJ Itcllk eniire aiiribuiels “class” “klass” e| ”p". ailribulels “class” “klass" aiiribuiels “id" “hoge" el”E". eniire. el”F” el”E". /e| "F” e| ”E". aiiribuiesalisfies”hoge”(consi True) e| ”E". aiiribuiels”hoge’"’hage" el”E". aiiribulesaiisfies "hoge” l“hage" ‘isPrefixOf‘) lndexing(el”p") . index 0 lndexinglel"p") . indexl indexing (el"p") . indices odd f£$’1i4nI1o“— * . klass p. klass #hoge E F E > F E[hoge] E[hoge= “hage"] E[noge/ =“hage"] p: firsl—child p: n’rh—of—’rype( 2) p: nlh—of—lype(2n+l ) P. -.', '.. ' . a -9"/ ‘—CODE§’= E klass tb505XEi%D§§ klass t L 5 05X’&l%'3pE§? hoge&l, '5lD4‘EiEi%D§§ E03¥}«¥t03F EODIETUDF hogeFa'| E"&i§’_DEE§ nogeF: a'| $lZhagecEl, 5iIE"&i$ DEE? l'iage’C‘ll’: 'i‘EE~lIE7‘&i%’_D II sE'§i*}J0Dp§§ 2§EODpE§ firfifilfifi 0DpE§
  • 19. l‘9IJ : @l§tURL7a‘: i7§é‘tl: l’9” doc <- HTML . parseLBS <$> simpleHttp "http: //www. gochiusa. com/ " mapM_ T. putStrLn $ doc“. . root. entire. el"img" . attr"src” = > :5 runhaskell main. hs core_sys/ images/ main/ top/ pv_bt. png core_sys/ images/ main/ logo. png core_sys/ images/ main/ gnavi/ gnavi_ti. gif core_sys/ images/ main/ top/ gochi_cd0424_banner. jpg
  • 20. JSONcE73‘lZE ~ JSONOD3-“—’9fi$7l‘fi‘9“Z>0)lZi-3Lensbiliié F aeson—lensd: l,5l¥73“i’l5D7Z: /i‘y? '—§c‘: “ “ lens—aesoncEl, 5ekme’rilZal: Zo/ ‘y’§'—‘)73‘35Zo73 aeson—lensl: il¥13“‘Tsi"l’ED’C7El7‘€ >4‘/7:7"/ XL/ —C7EJ? l/7l"j: | D} “J’7'—: /“7'd:03_C IJZTekmei”rlZ<J: Zalens—aeson7a2l§5 Z & l
  • 21. l§lJ : “J’i"‘J’>"’—0D’9’i’A5’i’> doc <- decode <$> L. readFile "timeline. json" ForM_ (doc". ._Just. nonNull. _Array. traverse) $ ¥tweet -> do T. putStrLn $ tweet". key"user"'. key"screen_name". _String T. putStrLn $ tweet". key"text". _String
  • 22. Ebb - Lenslztillfiéliifllltliié '* 3i’~X lL/7I“_71‘—’>"lC77tX3"c7o0Dli’95 libfi ~ c7>*72i‘c‘T/ uLens‘C‘77"J E/ ucf/ ui’FD E b3: 5

×