Last active
August 29, 2015 14:16
-
-
Save k16shikano/faa43d2b3963b1202fa9 to your computer and use it in GitHub Desktop.
HXTでbodyタグだけテキストを書き換え
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{-# LANGUAGE Arrows, FlexibleContexts #-} | |
import Text.XML.HXT.Core | |
import Text.XML.HXT.Arrow.XmlArrow | |
main :: IO [String] | |
main = do | |
runX (readString [ ] "<html><head>foo</head><body><p>bar</p></body></html>" | |
>>> | |
processBottomUp | |
(processBottomUp | |
((changeText ("hoge"++)) `when` isText) | |
`when` hasName "body") | |
>>> | |
writeDocumentToString [ ] | |
) | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{-# LANGUAGE Arrows, FlexibleContexts #-} | |
import Text.XML.HXT.Core | |
import Text.XML.HXT.Arrow.XmlArrow | |
main :: IO [String] | |
main = do | |
runX (readString [ ] "<html><head>foo</head><body><p>foo</p><p class=\"sty\">bar</p></body></html>" | |
>>> | |
processBottomUp | |
(processBottomUp | |
(choiceA [ neg (hasAttrValue "class" (=="sty")) | |
:-> processChildren (changeText ("hoge"++) `when` isText) | |
, this | |
:-> this]) | |
`when` hasName "body") | |
>>> | |
writeDocumentToString [ ] | |
) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment